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

Assign player to own random property?

I'm making a cookie clicker game and there is 9 plates, or bases , 1 for each player. How do I make it when a player joins they get assigned a random one and the value of the value string change to the user's username. After that how do i deny other people clicking the owner's cookie and only the owner can click it. Lastly, avoid people owning a plate that is already owned. Thanks in advance.

1 answer

there is an event that happens when a player joins, you could make a table that contains all the unowned bases when the player joins, then do a randomizer to pick which base they will get, then you can change the string value to the player's name. When a player clicks on the cookie, do a check if the player's name is the same as the string value in the base and that will prevent other people from clicking the cookie.

game.Players.PlayerAdded:Connect(function(player) -- when a player is added
	local table = getUnownedBases() -- function that returns all unowned bases as a table
	local random = math.random(1, #table) -- random value from 1 to length of table
	local base = table[random]
	base.StringValue.Value = player.Name -- if stringvalue is child of base
end)

clickevent:Connect(function(player, base) -- when cookie is clicked
	if player.Name == base.StringValue.Value then
		-- stuff here
	end
end)

1 comment

0

Thanks im going to try this.

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