I am creating a script to prevent players from teleporting to long distances. There are many functions, but when I try to call this specific one, all functions return an error "attempt to call global (a nil value)". I tried to copy and paste the function in another script and it still gives the same error for that function.
This is the script:
local plr = game.Players.LocalPlayer
repeat wait() until plr.Character and plr.Character:FindFirstChild("Torso") and plr.Character:FindFirstChild("Humanoid")
local char = plr.Character
local hum = char.Humanoid
local MaxDistance = 250
local LastLocation = nil
local PASS = true
repeat wait(5) CheckPlayerLocation() until PASS == false
function CheckPlayerLocation()
if PASS and char ~= nil then
if LastLocation ~= nil then
local CurrentLocation = char.HumanoidRootPart.Position
local Distance = (CurrentLocation-LastLocation).Magnitude
if Distance > MaxDistance then
PASS = false
-- kicks player --
return
else
LastLocation = char.HumanoidRootPart.Position
end
else
LastLocation = char.HumanoidRootPart.Position
end
end
end
I don't understand why it considers it a "nil value", it looks fine to me, and every other function has no problem running when the "repeat wait(5) CheckPlayerLocation() until PASS == false" is deactivated. Maybe I'm doing something wrong with this part? If so I don't understand what that might be..

3 comments
It's because you call the function on line 11, but you don't make it until line 13, so on line 11 you call a function that doesn't exist
Oh yeah, I forgot about that. Thank you.
I can't mark this as answered because you wrote it as a comment, and it doesn't let me mark my own answer as correct