Player.CharacterAdded:Wait()
What do you believe this will return as it’s value?
That will return the Character instance of the Player, it’s why you also see
local character = Player.Character or Player.CharacterAdded:Wait()
If the character wasn’t loaded before the variable was set up, it waits for it to exist. Using a :Wait()
on an event also returns what the event would’ve returned I believe, hence why it works
1 Like
Yea, checks out. Wasn’t sure if they returned aynthing.
The code looks solid. I like the use of the Heartbeat:Wait() instead of Wait()
1 Like
I think the same applies to any event that you get a return from, so if you did
local delta = game:GetService("RunService").Heartbeat:Wait()
It would store the deltatime, the time since previous frame, into the variable.
And it’s always a good habit to use Heartbeat:Wait()
instead of the typical wait()
for things like this, prevents the chance of a long yield haha, unless framerates are bad of course
local Players = game:GetService('Players')
local pos = Vector3.new(496.5, 26, -378.2)
local function spawnPos(char)
game:GetService('RunService').Heartbeat:Wait()
char:WaitForChild('HumanoidRootPart').Position = pos
end
game.Players.PlayerAdded:Connect(function(player)
if player.Character then
spawnPos(player.Character)
end
player.CharacterAdded:Connect(spawnPos)
end)