Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

Parameters with Mouse Events?

Asked by 10 years ago

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

Log in to vote
-1
Answered by 10 years ago

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
I'd rather not have to write the whole script like that. I've done that before but it's too disorganized and repetitive. FearMeIAmLag 1161 — 10y
Ad

Answer this question