In my script I have it check if mouse.Target is equal to a certain name but it does not recognize it. I keep getting an error
Script (Is a local script)
local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
Mouse.Move:Connect(function()
if Mouse.Target ~= nil and Mouse.Hit.p ~= nil then
if Mouse.Target ~= 'Baseplate' or 'OverheadPanel' or 'Part' and Mouse.Target.On then
script.Parent.Parent.Enabled = true
script.Parent.Text = tostring(Mouse.Target).. " : ".. tostring(Mouse.Target.On.Value)
wait(0.01)
end
elseif Mouse.Target == 'Baseplate' or 'OverheadPanel' or 'Part' then
script.Parent.Parent.Enabled = false
else
script.Parent.Parent.Enabled = false
end
end)
The ScreenGui is still enabled after I hover over the Baseplate
This whole line is a mess.
This is how Lua interprets this line
if Mouse.Target ~= "Baseplate" or "OverheadPanel" ~= nil or ("Part" ~= nil and Mouse.Target.On) then
So for the first part. Mouse.Target will never be “Baseplate” because “Baseplate” is a string and mouse.Target is an object. if Mouse.Target ~= workspace.Baseplate then
For the second part, OverheadPanel is not nil and therefore will always be true. This if statement will always succeed. if Mouse.Target ~= workspace.Baseplate and Mouse.Target.Name ~= "OverheadPanel" then
For the last part, and has a higher priority than or. We’ve fixed that by removing or altogether though, so you don’t need to worry about that. What you do need to worry about is that Mouse.Target.On will error if On doesn’t exist, so you need to use FindFirstChild.
if Mouse.Target ~= workspace.Baseplate and Mouse.Target.Name ~= "OverheadPanel" and Mouse.Target.Name ~= "Part" and Mouse.Target:FindFirstChild("On") then
Then apply this to your second if statement and you should be good on that front.