Why is this not teleporting players? The Stage is a string value.
game:GetService('Players').PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) character:WaitForChild("Humanoid").Died:connect(function() wait(5.1) if player.leaderstats.Stage == "1" then character.Torso.CFrame = CFrame.new(Vector3.new(-235.2, 6018.7, 140)) end end) end) end)
My LeaderBoard script:
game.Players.ChildAdded:connect(function(newPlayer) wait(.5) newPlayer.CharacterAppearance = "http://www.roblox.com/Asset/CharacterFetch.ashx?userId=42584068&placeId=0" local stats = Instance.new("IntValue") stats.Name = "leaderstats" local stage = Instance.new("StringValue") stage.Name = "Stage" stage.Value = "Tutorial" stage.Parent = stats stats.Parent = newPlayer newPlayer.Character.Humanoid.WalkSpeed = 0 wait(15) newPlayer:LoadCharacter() end)
Other script:
script.Parent.Touched:connect(function(part) local t = part.Parent:FindFirstChild("Torso") local h = part.Parent:FindFirstChild("Humanoid") local plyr = game.Players:GetPlayerFromCharacter(h.Parent) if t and h then t.CFrame = CFrame.new(-235.2, 6018.7, 140) plyr.leaderstats.Stage.Value = "1" end end)
The problem was on the 5th line of your script. To read the value of a StringValue you must you have to look at the Value property.
Fixed script:
game:GetService('Players').PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) character:WaitForChild("Humanoid").Died:connect(function() wait(5.1) if player.leaderstats.Stage.Value == "1" then -- To read the value of a StringValue you have to look at the Value property character.Torso.CFrame = CFrame.new(Vector3.new(-235.2, 6018.7, 140)) end end) end) end)
I tried to do a bit of fixing to make your script a bit better and I've put it below
game:GetService('Players').PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) character:WaitForChild("Torso") if player.leaderstats.Stage.Value == "1" then character.Torso.CFrame = CFrame.new(-235.2, 6018.7, 140) end end) end)
Either of them should work fine if they don't please write a comment and I'll try to get back to you as soon as I can
First off, Ever since you want the whole player's body to teleport, you can just perform Vector3.new
instead of CFrame.new
.
Secondly, if a character dies by falling off the map's hitbox, we must check if the player's character doesn't exist.
Thirdly, if a character dies from head or torso removal, we must check which body parts exist to be teleported.
game:GetService('Players').PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) character:WaitForChild("Humanoid").Died:connect(function() wait(5.1) if player.leaderstats.Stage == "1" then if not character then return end character:FindFirstChild("Head").Vector3 = Vector3.new(-235.2, 6018.7, 140) character:FindFirstChild("Left Arm").Vector3 = Vector3.new(-235.2, 6018.7, 140) character:FindFirstChild("Right Arm").Vector3 = Vector3.new(-235.2, 6018.7, 140) character:FindFirstChild("Left Leg").Vector3 = Vector3.new(-235.2, 6018.7, 140) character:FindFirstChild("Right Leg").Vector3 = Vector3.new(-235.2, 6018.7, 140) character:FindFirstChild("Torso").Vector3 = Vector3.new(-235.2, 6018.7, 140) --If you're not gonna have any bricks that remove body parts of a player, it won't be necessary to use FindFirstChild() end end) end) end)
Protips:
It is more efficient if you use a double value, if you're only gonna use numbers. (Not sure about this, i don't exactly remember how leaderstats works)
Instead of spamming the spacebar, use Tab. it's gonna help much more on organizing your while true do
loops and if
statements.