(insert something here that gets me 10000000000000000000M rep)
Hi, its a me! BashGuy10. After playing a lot of farming games, i had inspiration to make my own, one of the problems i've encountered is: Stoping the player from placing on the same farm plot that already has a crop.
Does anybody know how to fix this?
I've already tryed using mouse.Target:GetChildren()
to see if there is not any crops already placed, but it stops the ability to even place!
Local script
local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() local currentobject = plr:FindFirstChild("CurrentObject") local UIS = game:GetService("UserInputService") local activekeycode = Enum.KeyCode.B local active = true local frame = script.Parent.Place local rp = game:GetService("ReplicatedStorage") local crops = rp:WaitForChild("CropModels") local event = rp:WaitForChild("PlaceCrop") for i, v in pairs(frame:GetChildren()) do local model = crops:FindFirstChild(v.Name) v.MouseButton1Click:Connect(function() if model then if not active and currentobject.Value ~= model then rp:WaitForChild("ChangeCrop"):FireServer(model) end end end) end UIS.InputBegan:Connect(function(input) if input.KeyCode == activekeycode then if active then print(active) active = false elseif not active then print(active) active = true end end end) local plantdb = false mouse.Button1Down:Connect(function() print("yeet") if active and not plantdb then print("yeet2") if mouse.Target.Name == "Plot" and not mouse.Target:GetChildren() then print("yeet3") event:FireServer(mouse.Target) end end end)
Server script
game.ReplicatedStorage.PlaceCrop.OnServerEvent:Connect(function(plr, target) print("yeet4") local clone = plr:FindFirstChild("CurrrentObject").Value:Clone() clone.Parent = target clone:SetPrimaryPartCFrame(target.CFrame) print("yeet65") end)
The best choice in my opinion would be Region3. It's like an invisible square that you check whether there's something inside of or not.
You can use one with whitelist and if there are any crops in that square you wouldn't allow placement. make sure to do the same for the server to make sure players can't farm where they shouldn't.