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

Parameters with Mouse Events?

I haven't used parameters much in the past, so I tried using them in this script to make it easier on myself. I thought the code would work fine at first, but when I ran it in play solo, there were no errors until I tried hovering over or clicking on one of the textbuttons. The output read "Players.Player1.PlayerGui.Control:18: attempt to index local 'button' (a number value)" when I tried to click on one of the buttons. I'm not sure if I'm using parameters right, but I thought I was. What am I doing wrong and is there anything I could improve upon? Any help will be appreciated.

wait(1)
game.StarterGui:SetCoreGuiEnabled("All", false)
player = game.Players.LocalPlayer
interface = player.PlayerGui.Interface
menu = interface.Menu
choices = interface.Choices
indoors = menu.Indoors
outdoors = menu.Outdoors
vehicle = menu.Vehicle

function hovering(button)
	if button.TextColor3 == Color3(165/255,165/255,165/255) then
		button.TextColor3 = Color3.new(200/255,200/255,200/255)
	end
end

function removing(button)
	if button.TextColor3 == Color3(200/255,200/255,200/255) then
		button.TextColor3 = Color3.new(165/255,165/255,165/255)
	end
end

function clicking(button)
	if button.TextColor3 ~= Color3(240/255,240/255,240/255) then
		indoors.TextColor3 = Color3.new(165/255,165/255,165/255)
		outdoors.TextColor3 = Color3.new(165/255,165/255,165/255)
		vehicle.TextColor3 = Color3.new(165/255,165/255,165/255)
		button.TextColor3 = Color3.new(240/255,240/255,240/255)
	end
end

indoors.MouseEnter:connect(hovering)
outdoors.MouseEnter:connect(hovering)
vehicle.MouseEnter:connect(hovering)
indoors.MouseLeave:connect(removing)
outdoors.MouseLeave:connect(removing)
vehicle.MouseLeave:connect(removing)
indoors.MouseButton1Down:connect(clicking)
outdoors.MouseButton1Down:connect(clicking)
vehicle.MouseButton1Down:connect(clicking)

1 answer

The parameter refers to the mouse location, not the button. You may have to write the hovering and removing functions for each individual button event, as of yet I can't see any way that you could do besides that, but there probably is. Also, I don't think you have to add the color value division, and you still add .new to Color3 in the if statement.

--Example
outdoors.MouseEnter:connect(function()
	if outdoors.TextColor3 == Color3.new(200,200,200) then
	outdoors.TextColor3 == Color3.new(165,165,165)
end)

1 comment

1

I'd rather not have to write the whole script like that. I've done that before but it's too disorganized and repetitive.

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