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

Can someone help with this rather simple but confusing for me code ?

Sooo i have a game that is basically a scientific game i guess you could say ( for example, innovation inc stuff ) and basically theres a security room and i want only certain players to spawn in it ( yes, i said spawn in it ) so heres the code :

local players = {"fusroda_man", "plasper15", "Cuxrs3d"}

game.Players.PlayerAdded:connect(function(plr)
		for i = 1, #players do
			if players[i] == plr.Name then
			local players.RespawnLocation = game.Workspace.securityspawn.SpawnLocation
		end
	end
end)

1 answer

✓ Accepted answer

Try doing this code instead:

local players = {"fusroda_man", "plasper15", "Cuxrs3d"}

game.Players.PlayerAdded:Connect(function(plr)
	for _, player in ipairs(players) do
		if plr.Name == player then
			plr.RespawnLocation = workspace.securityspawn.SpawnLocation
		end
	end
end)

Firstly, use ipairs or pairs instead of just a for loop. Secondly, you can't assign a variable into the player. Thirdly, player properties can't be assigned to variables with the dot operator. Hope this helps!

1 comment

0

It works exactly like how i wanted it to ! Thanks so much, i've been trying to get it working for almost a week now

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