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

Why is my button not doing anything?

I was just trying to make a simple button. But of course the button decides not to work because I probably made a mistake. I am scripting in a local script just putting this out there. Someone please help me.

Code:

--Made By: Troloolooolooll

local button = script.Parent

button.MouseEnter:connect(function()
	button.BackgroundColor3(141, 141, 141)
end)

button.MouseButton1Click:connect(function()
	local player = game.Players.LocalPlayer
	print(player.Name)
end)

button.MouseLeave:connect(function()
	button.BackgroundColor3(80, 80, 80)
end)

Edited: I put my gui in a folder. When I took it out of the folder it worked.

1 answer

✓ Accepted answer

When changing the Color value of an object in RGB, you need to use Color3.new. But, you would also need to divide all three values, R, G, and B, by 255 or it will always be completely black or completely white. Inclusively make sure that the button is visible and accessible on the screen. My button was a TextButton residing in a ScreenGui.

local button = script.Parent

button.MouseEnter:connect(function()
	button.BackgroundColor3 = Color3.new(141/255, 141/255, 141/255)
end)

button.MouseButton1Click:connect(function()
	local player = game.Players.LocalPlayer
	print(player.Name)
end)

button.MouseLeave:connect(function()
	button.BackgroundColor3 = Color3.new(80/255, 80/255, 80/255)
end)

7 comments

0

Thank you, but the fact is the functions aren't even being ran. So like nothing is happenning

0

Showing entire script, also make sure that your button is visible on the screen, such as in a ScreenGui.

0

I am showing my entire script. Also the button is visible and active.

0

When running my script, both in Studio's Test Mode and playing in an actual server using it, the button worked fine. Without the Color3.new phrase inserted into the code, the script just gives the Button 3 numbers, with no idea how to use them.

0

So do you know what the problem is or?

0

I was sure the Color3 was the only problem. Did you at least insert the new code to see for yourself?

0

Yes, I inserted the new code and didn't work, but the problem is that the functions aren't being ran.

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