--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
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