Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Radius checking not working?

Asked by
wackem 50
8 years ago

So whenever I try to use the script, the output says "Attempting to compare two user data values", and I don't know how to fix it. Can anyone help?

Here's my code:

local tool = script.Parent

local mychar
local myhum

tool.Equipped:connect(function()
    mychar = tool.Parent
    myhum = mychar:WaitForChild("Humanoid")
    myhum.WalkSpeed = 0
    hold = myhum:LoadAnimation(tool:WaitForChild("Hold"))

    hold:Play()

    for _,part in pairs(workspace:GetChildren()) do
        if part:IsA("Part") then
        if part.CFrame <= mychar.Torso.CFrame + Vector3.new(8, 8, 8) then
            print(part.Name)
            end
        end
    end
end)

tool.Unequipped:connect(function()
    hold:Stop()
    myhum.WalkSpeed = 16
end)

1 answer

Log in to vote
1
Answered by
drahsid5 250 Moderation Voter
8 years ago

You cannot compare CFrames,

if Part.CFrame <= Otherpart.CFrame then

end

Won't work, use magnitude:

if (Part.Position - Otherpart.Position).Magnitude <= 20 then

end
Ad

Answer this question