Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can i prevent players placing crops on the same farm plot location?

(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

0

bro

0

yes?

0

no.

0

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.

0

speech 100

1 answer

✓ Accepted answer

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.

3 comments

0

i'll look into this, see what i can manage to do.

0

You Should get the owner of the other's plot and do Like if Owner.Value == plr if objectvalue of string or whatever do plr.Name then do the place script else print("Wrong Plot")

0

managed to make it worked!

This discussion is preserved as it was. New answers, comments, and votes are closed.