Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What does this mean and how do I fix it?

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

1 comment

0

I basically want it so that if you are 5 studs away from the door in any angle a gui will pop up

1 answer

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

3 comments

0

Thank you so much!

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

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.