Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 10 years ago

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

Log in to vote
0
Answered by
2eggnog 981 Moderation Voter
10 years ago

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)
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. DEVEL0PMENT 35 — 10y
0
Hm, that's interesting. I tested it and it works. Try replacing wait() with wait(.1) 2eggnog 981 — 10y
0
Works now. I really appreciate your help. DEVEL0PMENT 35 — 10y
Ad

Answer this question