How to only claim once, and not let other players claim

I want to make a part that you can claim(Achieved), but I also want it to be claimed once by the same person, and not let it be able to claim again.

I can’t get it to be only claimed once, it keeps going in the player many times, and is able to claimed by others once already claimed.

I tried if statements and while loops, none worked because it will still do the same thing.

Script Inside Click Detector:

script.Parent.MouseClick:Connect(function(player)
	if Claimed == nil then
		script.Parent.Parent.BillboardGui.TextLabel.Text = "Owned By No One" 
		local Claimed = Instance.new("NumberValue")
		Claimed.Name = "Claimed"
		Claimed.Value = 0
		Claimed.Parent = player
		
	if script.Parent.Parent.BillboardGui.TextLabel.Text == "Owned By No One" then
		if Claimed.Value == 0 then
			Claimed.Value = 1
			if Claimed.Value == 1 then
					script.Parent.Parent.BillboardGui.TextLabel.Text = "Owned By "..player.Name
				end
			end
		end
	end
end)

Thank you!

just make a object value and check if a players name has already claimed it

1 Like

I’d make a bool value for this. ( Inside the script or in a service players can’t abuse with exploits, idk which ones those are right now if someone could clarify that would be nice. )

Set it to true if the player collects it, check if the player has already collected the item with an “if then” statement, and set the value to false if you want the player to collect the item again.

Something like this I guess:

local playerHasCollectedItem = false
if playerHasCollectedItem == false then
print("Player has not gotten the item")
do

1 Like

Just realized I said nothing about actually getting the players name or Id. I would get the playersId, not the name as they can change it.

Basically what @Fxllen_Developer said.

1 Like

Cleaned up code as in your script editor there were red lines symbolising syntax errors.

local Claimed
script.Parent.MouseClick:Connect(function(player)
	if Claimed == nil then
		script.Parent.Parent.BillboardGui.TextLabel.Text = "Owned By No One" 
		Claimed = Instance.new("NumberValue")
		Claimed.Name = "Claimed"
		Claimed.Value = 0
		Claimed.Parent = player
		
	if script.Parent.Parent.BillboardGui.TextLabel.Text == "Owned By No One" then
		if Claimed.Value == 0 then
			Claimed.Value = 1
			if Claimed.Value == 1 then
					script.Parent.Parent.BillboardGui.TextLabel.Text = "Owned By "..player.Name
				end
			end
		end
	end
end)
1 Like

To add to what I was saying, I would also do what @Reditect had said. Because what could happen is that the player did claim some thing, but hasn’t collected it yet. So you could create both a bool and object value in this case. Object Value for player name and BoolValue if something has been collected.

1 Like

can’t get it to be only claimed once, it keeps going in the player many times, and is able to claimed by others once already claimed.

Just disconnect the function after it is claimed once.

1 Like