Ad
Log in to vote
0

Mouse.hit Gui not going away when looking away from object ?

Asked by 19 days ago
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()


UIS.InputChanged:Connect(function()
    if mouse.Target then
        if mouse.Target.Interact then
            script.Parent.Enabled = true
        else 
            script.Parent.Enabled = false
        end
    end
end)

So basically this script enables a gui if the object has an intvalue called interact in it. But when I look away from that object the gui does not go away. I probably did this very wrong so please help

1 answer

Log in to vote
0
Answered by 19 days ago

Sorry but I solved my own question....

local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()


UIS.InputChanged:Connect(function()
    if mouse.Target then
        if mouse.Target:FindFirstChild('Interact') then
            script.Parent.Enabled = true
        else
            script.Parent.Enabled = false
        end
    end
end)
Ad

Answer this question