Ad
Log in to vote
0

[solved] Why wont my script teleport players?

Asked by 1 month ago
Edited 1 month ago

So I made a simple script to teleport all players to one point after a function is called, but for some reason It does not teleport anyone. I didnt get any error in output and yes, I am sure the function runs properly. Here is the script I am using:

local proximity = script.Parent
local playersS = game:GetService("Players")
local players = playersS:GetChildren()

proximity.Triggered:Connect(function()
    for i,v in pairs(players) do
        v.Character.HumanoidRootPart.CFrame = workspace.playertpspawn.CFrame
    end
    proximity.Enabled = false
end)

Does someone know what am I doing wrong?

edit: I have just noticed that the issue is probably not with the v.Character.HumanoidRootPart.CFrame = workspace.playertpspawn.CFrame but with the for function, it just does not run.

1 answer

Log in to vote
0
Answered by 1 month ago

I just resolved it, the code with the player variables ran before even players loaded, so the table was empty. Moving ~~~~~~~~~~~~~~~~~ local playersS = game:GetService("Players") local players = playersS:GetChildren() ~~~~~~~~~~~~~~~~~ to the function fixed the issue

Ad

Answer this question