So I basically my problem is When someone touches a part it gives them a Win,
But what im trying to do is make whats inside the script not happen for others
so I have a localscript
local WinEvent = game.ReplicatedStorage.Events.WinEvent
local player = game.Players.LocalPlayer
local hasPressed = false
local RestartGame = game.ReplicatedStorage.Events.RestartGame
workspace.WinPart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChildOfClass("Humanoid") and hasPressed == false then
WinEvent:FireServer(player.Name)
workspace.WinPart.BrickColor = BrickColor.new("Bright green")
hasPressed = true
wait(5)
RestartGame.OnClientEvent:Connect(function()
hasPressed = false
workspace.WinPart.BrickColor = BrickColor.new("Institutional white")
end)
end
end)
because If I ran it on the server it would be really hard to have a debounce serversided because I wwould have to make a debounce for all the players on the server, but instead I tried to make a debounce player sided so I would have to do all this extra stuff
local WinEvent = game.ReplicatedStorage.Events.WinEvent
local player = game.Players.LocalPlayer
local hasPressed = false
local RestartGame = game.ReplicatedStorage.Events.RestartGame
script.Parent.Touched:Connect(function(hit)
local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if Player then
if hasPressed == false then
WinEvent:FireServer(player.leaderstats.Wins.Value, 1)
workspace.WinPart.BrickColor = BrickColor.new("Bright green")
hasPressed = true
wait(5)
RestartGame.OnClientEvent:Connect(function()
hasPressed = false
workspace.WinPart.BrickColor = BrickColor.new("Institutional white")
end
end
end)