Hello! I recently have been remaking a very old tycoon I made 2 years ago, and I have been trying to make a plot selection system. The selection system works perfectly except for detecting if the plot is occupied. I have been trying to make it tell the user if it’s occupied from the value in an InvtValue located in workspace, but it won’t work. Btw, there are three different plotnum InvtValues, the two in Workspace are what changes and what is detected if it is a certain number. I have tried everything I can think of but it won’t work, if you are able to help, that would be amazing!
Script (Localscript)
local taken = game.Workspace.plotnum
script.Parent.MouseButton1Click:Connect(function()
taken = false
for i, v in pairs(game.Players:GetPlayers()) do
if v.MyPlot.Value == script.Parent.Parent.Frame.plotname.plotnum.Value then
taken = true
end
end
if game.Workspace.plotnum.Value == 1 then
script.Parent.Text = "Taken"
wait(3)
script.Parent.Text = "Select"
else
game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = workspace.Plots[script.Parent.Parent.Frame.plotname.plotnum.Value].CFrame * CFrame.new(0,3,0)
workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
game.Players.LocalPlayer.MyPlot.Value = script.Parent.Parent.Frame.plotname.plotnum.Value
game.Workspace.plotnum.Value = 1
script.Parent.Parent.Enabled = false
end
end)
script.Parent.MouseButton1Click:Connect(function()
if game.Workspace.plotnum2.Value == 2 then
script.Parent.Text.Value = "Taken"
wait(3)
script.Parent.Text.Value = "Select"
else
game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = workspace.Plots[script.Parent.Parent.Frame.plotname.plotnum.Value].CFrame * CFrame.new(0,3,0)
workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
game.Players.LocalPlayer.MyPlot.Value = script.Parent.Parent.Frame.plotname.plotnum.Value
game.Workspace.plotnum2.Value = 2
script.Parent.Parent.Enabled = false
end
end)
Are you editing the values from a local script? Like, if you own a plot? If that’s the case, you cannot edit it on the client as it simple won’t replicate to the server, fire an event to change any values outside of the client objects. (UI’s as an example.)
Yes, whenever someone clicks select, the Localscript updates the IntValue in Workspace to 2. Then if someone else tries to select it, it wouldn’t let them due to the value being 2
It only updates the value on the client, not on the server as I said. Local scripts do not replicate changes made to the server. You can see this for yourself if you test in server mode and look at the values before and after claiming the plot.
local taken = game.Workspace.plotnum
local remoteEvent = game:GetService("ReplicatedStorage").FireLol
script.Parent.MouseButton1Click:Connect(function()
taken = false
for i, v in pairs(game.Players:GetPlayers()) do
if v.MyPlot.Value == script.Parent.Parent.Frame.plotname.plotnum.Value then
taken = true
end
end
if game.Workspace.plotnum.Value == 1 then
script.Parent.Text = "Taken"
wait(3)
script.Parent.Text = "Select"
else
-- give them the plot
game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = workspace.Plots[script.Parent.Parent.Frame.plotname.plotnum.Value].CFrame * CFrame.new(0,3,0)
workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
game.Players.LocalPlayer.MyPlot.Value = script.Parent.Parent.Frame.plotname.plotnum.Value
game.Workspace.plotnum.Value = 1
script.Parent.Parent.Enabled = false
end
end)
script.Parent.MouseButton1Click:Connect(function()
if game.Workspace.plotnum2.Value == 2 then
script.Parent.Text.Value = "Taken"
wait(3)
script.Parent.Text.Value = "Select"
else
game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = workspace.Plots[script.Parent.Parent.Frame.plotname.plotnum.Value].CFrame * CFrame.new(0,3,0)
workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
game.Players.LocalPlayer.MyPlot.Value = script.Parent.Parent.Frame.plotname.plotnum.Value
remoteEvent:FireServer()
game.Workspace.plotnum2.Value = 2
script.Parent.Parent.Enabled = false
end
end)
It removed the errors in the console, but it still lets the user claim the plot when someone else already did. No errors pop up for any of the scripts now.
Most ideal case for you would be to make a folder for the plot, put an IntValue for the plot number and a BoolValue to be set to true if someone owns the plot meaning someone else cannot override it. Name the folder the players name.
Edit: I am not writing your script for you.
Edit 2: Going off to sleep, won’t be able to assist further. Good luck and someone else will return if you’re still struggling. Mark my post as the solution to your original post.