Bug Registration system

hello, im making that you can register on a ring to participate in a match.But my problem is that if you register, someone else can register at the same place.

heres the hierarchy

image
image
heres the registration code

script.Parent.ProximityPrompt.Triggered:Connect(function(plr)
	if plr:FindFirstChild("PlrStats"):FindFirstChild("isRegistred").Value == false then

			script.Parent.Parent.PlayerOne.Value = plr.Name
			plr:FindFirstChild("PlrStats"):WaitForChild("isRegistred").Value = true
			script.Parent.SurfaceGui.TextLabel.Text = "Player One : "..plr.Name

	end
end)

script.Parent.Parent.PlayerOne:GetPropertyChangedSignal("Value"):Connect(function()
	script.Parent.SurfaceGui.TextLabel.Text = "Player One : "..script.Parent.Parent.PlayerOne.Value
end)

You could add a check statement to see whether a player already has claimed that ring or not

script.Parent.ProximityPrompt.Triggered:Connect(function(plr)
    local plrStats = plr:FindFirstChild("PlrStats")
    if plrStats and plrStats:FindFirstChild("isRegistered") then
        local isRegistered = plrStats.isRegistered.Value
        if not isRegistered then
            script.Parent.Parent.PlayerOne.Value = plr.Name
            plrStats.isRegistered.Value = true
            script.Parent.SurfaceGui.TextLabel.Text = "Player One: " .. plr.Name
        else
-- if the player tries to claim and someone already has here you could add additional code for that siutuation
        end
    end
end)

script.Parent.Parent.PlayerOne:GetPropertyChangedSignal("Value"):Connect(function()
    script.Parent.SurfaceGui.TextLabel.Text = "Player One: " .. script.Parent.Parent.PlayerOne.Value
end)

isRegistered is a value for the player, not the the ring system

My bad, so instead you could check if player1 value is empty or not

script.Parent.ProximityPrompt.Triggered:Connect(function(plr)
    local playerStats = plr:FindFirstChild("PlrStats")
    local parent = script.Parent

    if not parent.PlayerOne.Value then
        parent.PlayerOne.Value = plr.Name
        playerStats.isRegistered.Value = true
        script.Parent.SurfaceGui.TextLabel.Text = "Player One: " .. plr.Name
    elseif not parent.PlayerTwo.Value then
        parent.PlayerTwo.Value = plr.Name
        playerStats.isRegistered.Value = true
        script.Parent.SurfaceGui.TextLabel.Text = "Player Two: " .. plr.Name
    else
        -- If both PlayerOne and PlayerTwo are already claimed
        print("Both slots are already claimed.")
    end
end)

parent.PlayerOne:GetPropertyChangedSignal("Value"):Connect(function()
    script.Parent.SurfaceGui.TextLabel.Text = "Player One: " .. parent.PlayerOne.Value
end)

parent.PlayerTwo:GetPropertyChangedSignal("Value"):Connect(function()
    script.Parent.SurfaceGui.TextLabel.Text = "Player Two: " .. parent.PlayerTwo.Value
end)

Thanks, also how would i reset that value if the player that registered left?

Nevermind i figured it out. Thanks for the help tho

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.