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

{SOLVED}How to properly check a value in player on respawn?

Basically I have a boolvalue inside the player that denominates whether or not the player is in jail. If the value is true, (the value is changed by an arrest tool) then the player gets moved to a part (JailSpawn). Only thing is, I don't want to use teams. Can anyone help? I'm probably doing this all wrong, I'm new at scripting.

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
	if player.Jailed.Value == true then
		character:MoveTo(game.Workspace.JailSpawn.Position)
	end
	end)
	end)

That's what I have so far. Thanks in advance.

1 answer

✓ Accepted answer

You were extremely close. Roblox was just moving your character to the default spawn at the same time you were trying to move it to the jail spawn. The solution is to add a wait() before moving it. It's also recommended that you CFrame the torso rather than moving the entire character so that people won't spawn on top of the jail.

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		if player.Jailed.Value == true then
			wait(.1)
			local torso = character:WaitForChild("Torso")
			torso.CFrame = CFrame.new(game.Workspace.JailSpawn.Position+Vector3.new(0,3,0))
		end
	end)
end)

3 comments

0

For some reason it's not working. I don't doubt your code, but it still won't move you if the value is true.

0

Hm, that's interesting. I tested it and it works. Try replacing wait() with wait(.1)

0

Works now. I really appreciate your help.

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