I’m currently trying to figure out why this won’t work for 2 players probably a stupid mistake, or how im running it.
Basically what im doing is making a loop that runs once with wwd, (while wait() do) and then having it send a remote to the server and break.
After the server recieves it it gives them a plot which works fine, but the local player script only works for one person.
The Script that I tried:
while wait() do
if game.Players.LocalPlayer.OwnsAPlot.Value == false then
game.ReplicatedStorage.Events.giveplot:FireServer()
print("fired giveplot")
wait(100)
break
end
end
db = false
while (game.Players.LocalPlayer.OwnsAPlot.Value == false and db == false) do
db = true
game.ReplicatedStorage.Events.giveplot:FireServer()
print("fired giveplot")
wait(certain time)
db = false
end
the wait 100 is not a debounce system, and what im showing is a proper one.
Use the Changed event instead of a while loop, it’s more efficient:
local player = game.Players.LocalPlayer
local debounce = true
player.OwnsAPlot.Changed:connect(function(value)
if debounce then
debounce = false
game.ReplicatedStorage.Events.giveplot:FireServer()
print("Fired")
wait() -- I recommend *not* using a wait() function here, use a BindableEvent or something to tell the script when the event is complete
debounce = true
end
end)
Yours is excessive. Using a variable only matters if the code has a chance to run multiple times before the first iteration is finished. Since this is a loop and not a function, a wait will suffice, but I wouldn’t call it a debounce. Regardless, a debounce just isn’t necessary in a loop.
local Connection
Connection = game.Players.LocalPlayer.OwnsAPlot:GetPropertyChangedSignal("Value"):Connect(function()
if game.Players.LocalPlayer.OwnsAPlot.Value == false then
game.ReplicatedStorage.Events.giveplot:FireServer()
Connection:Disconnect()
end
end)
Only detects if Value property changes, if false then fire event and Disconnect.
Local scripts fired once for everyone who joined because you used break which stoped the loop a complete solution is debounce so you should use
db = false
while wait() do
if game.Players.LocalPlayer.OwnsAPlot.Value == false and db == false then
db = true
game.ReplicatedStorage.Events.giveplot:FireServer()
print("fired giveplot")
wait(2)
db = false
end
end