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

Why aren't this mouse(Enter/Leave/Click) events firing?

Asked by
Mystdar 352 Moderation Voter
9 years ago

Trying to make it so can chose a class by pressing a Image Button, but it isn't working, I think the event is not firing. There is nothing in the Output, the parenting is correct, and it is in the PlayerGui.

Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
Button = script.Parent
Folder = script.Parent.Parent.Parent.Parent.Folder
Chosen_Yet = Folder.Chosen_Class -- Boolean that registers if they have chosen yet
Current = Folder.Current_Class

Colours = {BrickColor.new(152/255, 38/255, 40/255),
           BrickColor.new(75/255, 108/255, 90/255),
           BrickColor.new(152/255, 38/255, 40/255)}

function Enter()
    if not Chosen_Yet then
        Button.ImageColor3 = BrickColor.new(156/255, 156/255, 156/255) -- Light Grey
        Current.Value = Button.Parent.Name
    end
end

Button.MouseEnter:connect(Enter)

function Leave()
    if not Chosen_Yet then
        Button.ImageColor3 = BrickColor.new(68/255, 68/255, 68/255) -- Dark grey
    end
end

Button.MouseLeave:connect(Leave)

function Click()
    if not Chosen_Yet and not Current then
        Button.ImageColor3 = Colours[1]
        Current.Value = script.Parent.Name
        Chosen_Yet.Value = true
    end
end


Button.MouseButton1Up:connect(Click)

2 answers

Log in to vote
1
Answered by 9 years ago
Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
Button = script.Parent
Folder = script.Parent.Parent.Parent.Parent.Folder
Chosen_Yet = Folder.Chosen_Class -- Boolean that registers if they have chosen yet
Current = Folder.Current_Class

Colours = {BrickColor.new(152/255, 38/255, 40/255),
           BrickColor.new(75/255, 108/255, 90/255),
           BrickColor.new(152/255, 38/255, 40/255)}

function Enter()
    if not Chosen_Yet.Value then
        Button.ImageColor3 = BrickColor.new(156/255, 156/255, 156/255) -- Light Grey
        Current.Value = Button.Parent.Name
    end
end

Button.MouseEnter:connect(Enter)

function Leave()
    if not Chosen_Yet.Value then
        Button.ImageColor3 = BrickColor.new(68/255, 68/255, 68/255) -- Dark grey
    end
end

Button.MouseLeave:connect(Leave)

function Click()
    if not Chosen_Yet.Value then --and not Current? I don't understand what you mean by that when it's a stringValue
        Button.ImageColor3 = Colours[1]
        Current.Value = script.Parent.Name
        Chosen_Yet.Value = true
    end
end


Button.MouseButton1Up:connect(Click)

--[[
add the .Values to the BoolValues, before you were basically asking the compiler if Chosen_Yet instance was not not nil (or nil) so it never executed.
]]
Ad
Log in to vote
0
Answered by 9 years ago
Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
Button = script.Parent
Folder = script.Parent.Parent.Parent.Parent.Folder
Chosen_Yet = Folder.Chosen_Class -- Boolean that registers if they have chosen yet
Current = Folder.Current_Class
Colours = {BrickColor.new(152/255, 38/255, 40/255),
           BrickColor.new(75/255, 108/255, 90/255),
           BrickColor.new(152/255, 38/255, 40/255)}
function Enter()
    if not Chosen_Yet then
        Button.ImageColor3 = UDim2.new(156/255, 156/255, 156/255) -- Light Grey
        Current.Value = Button.Parent.Name
    end
end

Button.MouseEnter:connect(Enter)

function Leave()
    if not Chosen_Yet then
        Button.ImageColor3 = UDim2.new(68/255, 68/255, 68/255) -- Dark grey
    end
end
Button.MouseLeave:connect(Leave)
function Click()
    if not Chosen_Yet and not Current then
        Button.ImageColor3 = Colours[1]
        Current.Value = script.Parent.Name
        Chosen_Yet.Value = true
    end
end
Button.MouseButton1Click:connect(Click)

try this i think it will work. but it will only work in a local script so copy this and paste it into a local script if you haven't already

Answer this question