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

Teleportation Script | No errors but doesn't teleport...?

Asked by
N43FGXL 169
5 years ago

I am trying to make a script that will teleport players to a random 'spawn' location within a map. The 'map' variable is already defined earlier in the script. (This is a chunk of my larger script)

local MapPlayerSpawns = map.SpawnLocations:WaitForChild("PlayerSpawns"):GetChildren()
    function tp()
        local Players = game.Players:GetPlayers()
        for i,v in pairs(Players) do
            local randomPTP = math.random(1,#MapPlayerSpawns)
            local IndSpawn = MapPlayerSpawns[randomPTP]
            wait(0.1) -- For loading times
            local plr = Players[i]
            plr:WaitForChild("Character"):SetPrimaryPartCFrame(IndSpawn.CFrame + Vector3.new(0, 5, 0)) -- Script works but doesn't teleport the player.
        end
    end
    tp()

Note: This isn't a duplicate question, I asked a different question with a similar script earlier.

I hope you can help me.

1
You can Find A Random Map By Just using "MapPlayerSpawns[math.random(1,#MapPlayerSpawns)" lol! that will return 1 Random Spawn From the Map Specificaly, so get rid of line 5 and 6 and replace it with that! Tizzel40 243 — 5y
0
I know, but that doesn't solve my problem. N43FGXL 169 — 5y
0
It doesnt? Tizzel40 243 — 5y
0
Of course it doesn't, he is already doing that just with two variables instead of one line. CeramicTile 847 — 5y

2 answers

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

I believe "Character" is a property and not a child of the player object. Also you're looping through a list of players so you don't need to do Players[i] or anything like that to get the player.

Lets see if I can fix this for ya.

local MapPlayerSpawns = map.SpawnLocations:WaitForChild("PlayerSpawns"):GetChildren()
function tp()
    local Players = game.Players:GetPlayers()
    for i,v in pairs(Players) do
        local randomPTP = math.random(1,#MapPlayerSpawns)
        local IndSpawn = MapPlayerSpawns[randomPTP]
        wait(0.1) -- For loading times
        if (v.Character) then
          v.Character:SetPrimaryPartCFrame(IndSpawn.CFrame + Vector3.new(0, 5, 0)) -- Script works but doesn't teleport the player.
        end
    end
end
tp()

So I just check if the player currently has a character and if they have it, teleport them.

1
Ah... I didnt even catch that lol! <:D>, good point @CeramicTile! <:D>! Tizzel40 243 — 5y
Ad
Log in to vote
1
Answered by
Tizzel40 243 Moderation Voter
5 years ago

Just Use the Character's Humanoid Root Part, instead of wasting your energy writing out The Primary Part CFrame!

And Also as @CeramicTile Said, the Character is not a property of the Player lol! <:D>!

----T40! ,2019

<:D>!

Answer this question