(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)

5 comments
bro
yes?
no.
Maybe from within the same server side script that shows all players a crop in a specific spot, you can have an isAvailable boolean value that is checked when the player selects the spot to plant. If false, then is doesn't allow them to.
speech 100