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
local function GetDistance(p1,p2)
local Distance = (p1.Position - p2.Position).magnitude
return Distance
end
players = game:GetService("Players")
local function start()
local character = players.LocalPlayer.Character.PrimaryPart
local button = script.Parent
while wait(0.1) do
if GetDistance(button - character) > 10 then
print("E")
end
end
end
game.Players.PlayerAdded:Connect(function()
game.Players.LocalPlayer.CharacterAdded:Connect(start)
end)
