Hello.
I am currently making a player pad claiming system. Only one player can claim the pad and it will be theirs until they leave. This works, however, 2 players are able to touch it at the same time, and if they do, they will be able to break it completely. It becomes unclaimable, and no player is then able to claim it for themselves. I am unsure how to fix this, and I also do not know the cause. Here is my script:
local Pad = script.Parent
local Debounce = false
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvents = ReplicatedStorage:WaitForChild("Remote Events (Main)")
local IsClaimed = Pad.Parent.IsClaimed
local Aquariums = workspace.Map.Aquariums
Pad.Touched:Connect(function(hit)
if not (Debounce) then
if IsClaimed.Value == false then
Debounce = true
local Player = Players:GetPlayerFromCharacter(hit.Parent)
local Character = Player.Character
local ClaimedValue = Player.PlayerGui.AquariumClaimed
if ClaimedValue.Value == true then
else
Aquariums.PlayerPad1:FindFirstChild("Name Tag").NameUI.Username.Text = hit.Parent.Name
Aquariums.PlayerPad1.Claimant.Value = hit.Parent.Name
RemoteEvents.Data:FireClient(Player)
script.Parent.Process.Disabled = false
ClaimedValue.Value = true
IsClaimed.Value = true
end
wait(1)
Debounce = false
if IsClaimed.Value == true then
if Player then
Players.PlayerRemoving:Connect(function(PlayerLeaving)
if PlayerLeaving == Player then
Aquariums.PlayerPad1:FindFirstChild("Name Tag").NameUI.Username.Text = "Not Claimed"
IsClaimed.Value = false
end
end)
end
else
return end
end
end
end)
I am unsure why this happens, and would like some help. Thanks!
