Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --!nonstrict
- local rs = game.ReplicatedStorage
- local plrs = game.Players
- local debris = game:GetService("Debris")
- local set_farming = workspace:WaitForChild("SetFarming")
- local dropspot = workspace:WaitForChild("Dropspot")
- local plants = rs.Plants
- local pricesntaxes = require(rs.PricesnTaxes)
- local plant_waiting_time = 1
- local function IsInside(pos, part)
- local p = part.CFrame:PointToObjectSpace(pos)
- local s = part.Size / 2
- return math.abs(p.X) <= s.X and math.abs(p.Y) <= s.Y and math.abs(p.Z) <= s.Z
- end
- local inventory_scalas = {
- ["1"] = 20
- }
- local list_plants = {"Rice"}
- plrs.PlayerAdded:Connect(function(plr:Player)
- local folder = Instance.new("Folder",plr)
- folder.Name = "Plants"
- local money = Instance.new("NumberValue",plr)
- money.Name = "Cash"
- local owned_area = Instance.new("ObjectValue",plr)
- owned_area.Name = "owned_area"
- for i, plant in pairs(list_plants) do
- folder:SetAttribute(plant,0)
- end
- plr.CharacterAdded:Connect(function(char)
- char:SetAttribute("harvested",0)
- char:SetAttribute("earned",0)
- char:SetAttribute("inventory",1)
- char:GetAttributeChangedSignal("harvested"):Connect(function()
- if not char:FindFirstChild("inventory") then print("returned!") return end
- local inventory = char:FindFirstChild("inventory") :: Model
- local harvested = char:GetAttribute("harvested")
- local max_inventory = inventory_scalas[tostring(char:GetAttribute("inventory"))]
- for i = 1, 4 do
- local part = inventory:FindFirstChild(tostring(i))
- if part then
- local threshold if i == 1 then threshold = 1 else threshold = (i / 4) * max_inventory end
- if harvested >= threshold then
- part.Transparency = 0
- part.Effect.Enabled = true
- else
- part.Transparency = 1
- part.Effect.Enabled = false
- end
- end
- end
- end)
- end)
- end)
- plrs.PlayerRemoving:Connect(function(plr:Player)
- if plr.owned_area.Value ~= nil then
- local area = plr.owned_area.Value
- area.Owner.Value = nil
- area.Plants:ClearAllChildren()
- end
- end)
- local debounce = true
- dropspot.Touched:Connect(function(part)
- if not debounce then return end
- if part.Parent:FindFirstChildOfClass("Humanoid") then
- local char = part.Parent
- local plr = nil
- if plrs:GetPlayerFromCharacter(char) ~= nil then
- plr = plrs:GetPlayerFromCharacter(char)
- end
- if plr ~= nil then
- debounce = false
- if not char:FindFirstChild("inventory") or char:GetAttribute("earned")<=0 then debounce = true return end
- local inv = char:FindFirstChild("inventory")
- for i=4,1,-1 do
- inv[tostring(i)].Transparency = 1
- inv[tostring(i)].Effect.Enabled = false
- task.wait(.1)
- end
- plr.Cash.Value+=char:GetAttribute("earned")
- rs.NotifMoney:FireClient(plr,char:GetAttribute("earned"))
- char:SetAttribute("earned",0)
- char:SetAttribute("harvested",0)
- --inv:Destroy()
- --if char:FindFirstChild("Sickle") then char["Sickle"]:Destroy() end
- --if plr.Backpack:FindFirstChild("Sickle") then plr.Backpack["Sickle"]:Destroy() end
- debounce = true
- end
- end
- end)
- set_farming.Touched:Connect(function(part)
- if part.Parent:FindFirstChildOfClass("Humanoid") then
- local char = part.Parent
- local plr = nil
- if plrs:GetPlayerFromCharacter(char) ~= nil then
- plr = plrs:GetPlayerFromCharacter(char)
- end
- if plr ~= nil then
- if plr.Backpack:FindFirstChild("Sickle") or char:FindFirstChild("Sickle") then return end
- if not char:FindFirstChild("HumanoidRootPart") then return end
- local inv = rs.Plants[char:GetAttribute("inventory").."inventory"]:Clone()::Model
- inv.Parent = char
- inv.Name = "inventory"
- inv:PivotTo(char.HumanoidRootPart.CFrame)
- local weld = Instance.new("Weld",inv.Middle)
- weld.Part0 = char.UpperTorso
- weld.Part1 = inv.Middle
- rs.Plants.Sickle:Clone().Parent = plr.Backpack
- end
- end
- end)
- plants.Plant.OnServerEvent:Connect(function(plr:Player,position:Vector3,plant,remaining:NumberValue)
- local char = plr.Character:FindFirstChild("HumanoidRootPart")
- if char == nil then return end
- local can_plant = true
- local owned_area = nil
- local get_exact_pos = Vector3.new(position.X,49.7,position.Z)
- for _,area in pairs(workspace.FarmAreas:GetChildren()) do if area.Owner.Value == plr then owned_area = area end end
- if owned_area==nil then can_plant = false end
- if owned_area ~= nil then if not IsInside(get_exact_pos,owned_area) then can_plant = false end end
- if remaining.Value <= 0 then can_plant = false end
- if not can_plant then return end -- tüm koşullar tamam
- remaining.Value-=1
- if remaining.Value<=0 then
- char.Parent["Humanoid"]:UnequipTools()
- task.wait(.25)
- remaining.Parent:Destroy()
- end
- local plant_stage1 = rs.Plants:FindFirstChild(plant)["1STAGE"]:Clone() :: Model
- plant_stage1:PivotTo(CFrame.new(get_exact_pos))
- plant_stage1.Parent = owned_area["Plants"]
- plant_stage1:SetAttribute("wait",plant_waiting_time/4)
- plant_stage1:SetAttribute("stage",1)
- plant_stage1:SetAttribute("area",owned_area.Name)
- plant_stage1:SetAttribute("type",plant)
- end)
- -- areas handle
- task.wait(5)
- rs.Purchase.OnServerEvent:Connect(function(plr,p_type,area)
- if p_type ~= "land" then return end
- if area.Owner.Value ~= nil or plr.owned_area.Value ~= nil then return end
- local taxes=0 for _,tax in pairs(pricesntaxes["land"].tax) do taxes+=rs.Rules.Tax[tax].Value end
- local estimated_price = pricesntaxes["land"].price+((pricesntaxes["land"].price*taxes)/100) warn("calculated tax = ",((pricesntaxes["land"].price*taxes)/100))
- if plr.Cash.Value < estimated_price then return end
- plr.Cash.Value-=estimated_price
- plr.owned_area.Value = area
- area.Owner.Value = plr
- end)
- for _,area in pairs(workspace.FarmAreas:GetChildren()) do
- local clickdetector = area.ownership.Main.trigger :: ClickDetector
- local sg = area.ownership.Main.SG
- local owner = area.Owner :: ObjectValue
- clickdetector.MouseClick:Connect(function(plr)
- if area.Owner.Value ~= nil or plr.owned_area.Value ~= nil then return end
- rs.Purchase:FireClient(plr
- ,"land"
- ,"rbxassetid://97492019380655"
- ,area.Name
- ,"A wonderful place to grow up plants, take care of them, and sell them to earn money."
- ,area
- )
- warn("fired server")
- end)
- owner:GetPropertyChangedSignal("Value"):Connect(function()
- if owner.Value == nil then
- sg.Frame.Image.Visible = false
- sg.Frame.Displayname.Visible = false
- sg.Frame.Realname.Visible = false
- sg.Frame.vacant.Visible = true
- else
- sg.Frame.Image.Visible = true
- sg.Frame.Displayname.Visible = true
- sg.Frame.Realname.Visible = true
- sg.Frame.vacant.Visible = false
- sg.Frame.Image.Image = plrs:GetUserThumbnailAsync(owner.Value.UserId,Enum.ThumbnailType.HeadShot,Enum.ThumbnailSize.Size420x420)
- sg.Frame.Displayname.Text = owner.Value.DisplayName
- sg.Frame.Realname.Text = owner.Value.Name
- end
- end)
- end
- while task.wait(1) do
- for _, area in pairs(workspace.FarmAreas:GetChildren()) do
- local folder = area.Plants
- for _, plant:Model in pairs(folder:GetChildren()) do
- if plant:GetAttribute("wait") <= 0 and plant.Name~="4STAGE" then
- print(plant:GetAttribute("type"))
- local stager = rs.Plants:FindFirstChild(plant:GetAttribute("type"))[tostring(plant:GetAttribute("stage")+1).."STAGE"]:Clone() :: Model
- stager:PivotTo(plant.Center.CFrame * CFrame.Angles(0, math.rad(math.random(360)), 0))
- stager.Parent = workspace.FarmAreas:FindFirstChild(plant:GetAttribute("area")).Plants
- stager:SetAttribute("wait",plant_waiting_time/4)
- stager:SetAttribute("stage",plant:GetAttribute("stage")+1)
- stager:SetAttribute("area",plant:GetAttribute("area"))
- stager:SetAttribute("type",plant:GetAttribute("type"))
- debris:AddItem(plant,0)
- elseif plant.Name~="4STAGE" then
- plant:SetAttribute("wait",plant:GetAttribute("wait")-1)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment