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

MouseButton1Click won't work, help?

Asked by 9 years ago

So I'm trying to make a gui button make the other buttons fade away when pressed. But for some reason, the MouseButton1Click won't work. Here's the code:

script.Parent.MouseButton1Click(function()
    local sound = Instance.new("Sound")
    sound.SoundId = "rbxasset://sounds//clickfast.wav"
    sound.Parent = script.Parent.Parent
    sound:play()
    wait(.25)

    for i = 0, 1, 0.01 do
        script.Parent.Parent.SpawnButton.BackgroundTransparency = i
        script.Parent.Parent.SpawnButton.TextTransparency = i
        script.Parent.Parent.ShopButton.BackgroundTransparency = i
        script.Parent.Parent.ShopButton.TextTransparency = i
        wait(0.01)
    end
end)

Basically all that's keeping it from running is the MouseButton1Click event. This is what pops up in the output:

17:10:06.905 - Players.Player.PlayerGui.ScreenGui.StartScreen.ShopButton.L:2: attempt to call field 'MouseButton1Click' (a userdata value)

Help on what's happening, and why it confuses it for userdata value instead of a function would be appreciated!

1 answer

Log in to vote
0
Answered by
Damo999 182
9 years ago

The only thing that is wrong with the script is that you're connection line isn't complete.

script.Parent.MouseButton1Click:connect(function()---- i added :connect to the script
    local sound = Instance.new("Sound")
    sound.SoundId = "rbxasset://sounds//clickfast.wav"
    sound.Parent = script.Parent.Parent
    sound:play()
    wait(.25)

    for i = 0, 1, 0.01 do
        script.Parent.Parent.SpawnButton.BackgroundTransparency = i
        script.Parent.Parent.SpawnButton.TextTransparency = i
        script.Parent.Parent.ShopButton.BackgroundTransparency = i
        script.Parent.Parent.ShopButton.TextTransparency = i
        wait(0.01)
    end
end)
1
*facepalm* oh my gosh I can't believe I didn't notice something so simple... Thanks. ImmenseKassing 120 — 9y
0
It happens lol. Damo999 182 — 9y
Ad

Answer this question