Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
BashGuy10 384 Moderation Voter
4 years ago

(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)
0
bro gloveshun 119 — 4y
0
yes? BashGuy10 384 — 4y
0
no. royaltoe 5144 — 4y
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. uhohspaghettiy0o 15 — 4y
0
speech 100 GGRBXLuaGG 417 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

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.

0
i'll look into this, see what i can manage to do. BashGuy10 384 — 4y
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") Corrupt_Wolfstrik3r 51 — 4y
0
managed to make it worked! BashGuy10 384 — 4y
Ad

Answer this question