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

What does this mean and how do I fix it?

Asked by 8 years ago
--Interact Script

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local deb = false
local gui = plr.PlayerGui.Interact.Background
local dis = 5

while true do wait()
    if mouse.Target then
            if mouse.Target:FindFirstChild("canInteract") then
            local mag = (plr.Character.Torso.Position - mouse.Target.Position)
                if mag<=dis then 
                gui.Visible = true
                else
                gui.Visible = false
                end
            else
            gui.Visible = false
            end
    end
end

Error:Players.Player.PlayerGui.interactScript:13: attempt to compare userdata with number

0
I basically want it so that if you are 5 studs away from the door in any angle a gui will pop up AllianceScripter 30 — 8y

1 answer

Log in to vote
1
Answered by
funyun 958 Moderation Voter
8 years ago

I'd try working with Region3 on a project like this, but I've never used it before, so I'll go with your method. Anyway, Vector3's have a property called "Magnitude" to get the distance between points.

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local deb = false
local gui = plr.PlayerGui.Interact.Background
local dis = 5

while wait() do
    if mouse.Target then
        if mouse.Target:FindFirstChild("canInteract") then
            local mag = (plr.Character.Torso.Position - mouse.Hit.p).Magnitude --The distance between your torso and the target
            if mag<=dis then 
                gui.Visible = true
            else
                gui.Visible = false
            end
        else
            gui.Visible = false
        end
    end
end
0
Thank you so much! AllianceScripter 30 — 8y
0
I have another problem... If I put two doors in the same game it only opens the first door when I click the second one AllianceScripter 30 — 8y
0
Make the same code but change variables accordingly to your second door. Also, Region3's are a pain especially for something small like this. I've used Region3's for something similar and regret the time spent into doing so. But I don't regret the knowledge and uses that I learned Region3's can be used for. Legoman654 100 — 8y
Ad

Answer this question