Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I go about adding a Boolean to a player?

So in my game that I am making for me and my friends I have added multiple planets that contain thrones. What I'm trying to do is make it so that they can only claim one throne. So what if each player's character spawned with a Boolean value of true, but when they claimed a throne it would change it to false. Making them unable to claim another. I was thinking of using the CharacterAdded function, but this repeats after they respawn as well so the value would switch back to true when they do(I think). I also want too make it so that when they leave their thrones will be discarded and available to others. Should I be using another method to go about this? If so, what method?

Thanks in advance!

1 comment

0

tbh, I always wanted to make a game like that, like a grand strategy game but i have my own projects :P

1 answer

You've got the right idea, you just have to piece it together a bit more.

Use the PlayerAdded event to insert the value into the players upon joining.

game.Players.PlayerAdded:connect(function(plr) --PlayerAdded
	local val = Instance.new("BoolValue",plr); --Create the value
	val.Name = "canClaim";
	val.Value = true;
end)

Now that players have the enabled value, you want to turn that value off when they claim a planet.

(example code)

local planetClaim = script.Parent;

planetClaim.Touched:connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent);
	if plr then
		local val = plr:FindFirstChild("canClaim")
		if val.Value then --Check the canClaim value prior to claiming
			val.Value = false;
			
			--claim code

		end
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.