#Distance detection not working

4 messages · Page 1 of 1 (latest)

sharp quest
#

local cpname = game.Workspace.cp.PrimaryPart
local cpt = game.ReplicatedStorage.cp1

local function checkforcollisions(cpname, cpt)
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAppearanceLoaded:Wait()
print("character loaded")
local humanoidrootpart = character:WaitForChild('HumanoidRootPart')
print("humanrootpart loaded")
local part1 = cpname
local mag = (humanoidrootpart.Position - part1.Position).Magnitude

if mag <= 10 then
    print('part is close')
    cpt:FireServer()
end

end

while true do
checkforcollisions(cpname, cpt)
print("excecution started")
end

#

this is the code

#

print's are for debugging reasons, and nothing gets printed

sleek void
#

You need a wait in the 'while true do' loop otherwise the game will crash