how do i run a function when a character is added to the world?
i need to define the players character as a variable and i need to wait until its added its giving me index nil "CharacterAdded" for the line that should run the code
01 | local function GetDistance(p 1 ,p 2 ) |
02 | local Distance = (p 1. Position - p 2. Position).magnitude |
05 | players = game:GetService( "Players" ) |
07 | local character = players.LocalPlayer.Character.PrimaryPart |
08 | local button = script.Parent |
10 | if GetDistance(button - character) > 10 then |
17 | game.Players.PlayerAdded:Connect( function () |
18 | game.Players.LocalPlayer.CharacterAdded:Connect(start) |