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

Why doesn't my selection box hover not work?

I make a selection box hover but everytime I make it breaks even though it's the same line and it should work..

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

while wait() do
	if Mouse.Target ~=nil and Mouse.Target.Name == "Grab" then
		script.Parent.HoverLabel.Visible = true
		Mouse.Target.Select.Visible = true -- This line works but the other doesn't
	else
		script.Parent.HoverLabel.Visible = false
		Mouse.Target.Select.Visible = false -- < Error for some reason
	end
end

I don't know why?

6 comments

0

please add your code in a code block to make it readable :)

0

Also please tell us what the output error says

0

how to I make it into a code block?

0

Players.DayLighter_1995.PlayerGui.HoverGui.HoverClient:10: attempt to index nil with 'Select' is the output message.

0

while wait() do if Mouse.Target ~=nil and Mouse.Target.Name == "Grab" then script.Parent.HoverLabel.Visible = true Mouse.Target.Select.Visible = true -- This line works but the other doesn't else script.Parent.HoverLabel.Visible = false Mouse.Target.Select.Visible = false -- < Error for some reason end end

0

to put it in a code block you press the little lua icon that you see when you are editing or asking the questions and it will make a 'box' for you to put your code in

1 answer

✓ Accepted answer

You are getting an output error because in the else statement it says to make the "Select" box no longer visible, this will confuse the script because there is no SelectionBox to be found in the target.

So what you want to do is change your script into the following:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()


game:GetService("RunService").RenderStepped:connect(function()
	if Mouse.Target ~= nil and Mouse.Target.Name == "Grab" then --Checks if it is the right target
		if Mouse.Target:FindFirstChild("Select") then --CONFIRMS that we have a box
			local box = Mouse.Target:WaitForChild("Select") 
			box.Visible = true
			script.Parent.HoverLabel.Visible = true
			wait() 
			box.Visible = false --This will make the box no longer visible once the player is not targetting the item
			script.Parent.HoverLabel.Visible = false
		else
			script.Parent.HoverLabel.Visible = false
		end
	end
end)

1 comment

0

Thanks for this, I didn't copy your script cause' I would rather learn so I just made a module to do the selection box & to make the gui visible and I made a local script to activate it!

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