if i want the players to move to a different area, what do i do?
1 | wait( 5 ) |
2 | for i, v in pairs (game.Players:GetChildren()) do v.Character.Torso.CFrame = CFrame.new(Vector 3. new( 50 , 50 , 50 )) -- Change these coordinates to where you want the players to be teleported to |
3 | end |
^^^Above answer only works once (since the player's character changes every time he/she dies)^^^
A solution to this is to grab that player's character everytime it respawns:
01 | game.Players.PlayerAdded:connect( function (player) --grabs that specific player |
02 | player.CharacterAdded:connect( function (character) |
03 | repeat wait() until character.Torso.CFrame ~ = nil -- to make sure that the torso exists |
04 | character.Torso.CFrame = CFrame.new(workspace.Spawn.Position) + Vector 3. new( 0 , 10 , 0 ) -- set's the player's RESPAWN location |
05 | repeat wait() until --will wait() until desired teleportation is called |
06 | character.Torso.CFrame = CFrame.new( --Put desired position here<--) |
07 | character.Humanoid.Died:connect( function () |
08 | wait( 2 ) |
09 | player:LoadCharacter() --actually respawns the player once he/she has died |
10 | end |
11 | end |
12 | end |
Now if your wanting to teleport a player within a certain area (but not in an exact location), you'd use add this piece of code onto the one above:
1 | character.Torso.CFrame = CFrame.new(math.random(min,max),math.random(min,max),math.random(min,max)) |
2 |
3 | --Replace "MIN" and "MAX" with the minimum and maximum X,Y,Z coords |