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

Teleporting a Player When They Spawn?

Asked by 6 years ago

I'm trying to make it so the player teleports once they've spawned it, however it isn't working. It says player isn't a valid member of workspace.

local Players = game:GetService("Players")

function onPlayerAdded(player)
    print(player.Name .. " has entered the game")
    player.CharacterAdded:connect(function(character)
    local humanoid = character:FindFirstChild("Humanoid")
    humanoid.WalkSpeed = 0
    workspace:findFirstChild("Player")
    game.Workspace.Player.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(0, 50, 0))
    end)
    end


Players.PlayerAdded:connect(onPlayerAdded)

for _,player in pairs(Players:GetPlayers()) do
     onPlayerAdded(player)
end
0
Line 8 doesn't make sense. you're trying to find something called "Player". You probably just want to use Character.HumanoidRootPart.CFrame on line 9. RubenKan 3615 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

You used Vector3.new and not CFrame.new. Maybe that's the issue?

Ad
Log in to vote
0
Answered by
znepb 17
6 years ago
Edited 6 years ago

I looked through your script, and I resolved your error.

local Players = game:GetService("Players")

function onPlayerAdded(player)
    print(player.Name .. " has entered the game")
    player.CharacterAdded:connect(function(character)
      local humanoid = character:FindFirstChild("Humanoid")
      humanoid.WalkSpeed = 0
      character.HumanoidRootPart.CFrame = CFrame.new(0, 50, 0) --At the beggining, put "Character" instead of "workspace.Player". Also, consider using just CFrame then using Vector3.
    end)
end


Players.PlayerAdded:connect(onPlayerAdded)

for _,player in pairs(Players:GetPlayers()) do
     onPlayerAdded(player)
end

Hope this works!

0
That didn't seem to work, however the output doesn't show any errors. BouncingBrenda 44 — 6y

Answer this question