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

MouseButton1Click won't work, help?

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

✓ Accepted answer

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)

2 comments

1

facepalm oh my gosh I can't believe I didn't notice something so simple... Thanks.

0

It happens lol.

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