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

How do I change the transparency of a union on a click of a button gui?

I'm trying to make it so that when you click a button, the union (food)'s transparency goes 0. Right clicking changes it back to 1. Here is my script if needed.

local Food = game.Workspace.Food

function leftClick() Food.Transparency = 0 end

function rightClick() Food.Transparency = 1 end

script.Parent.MouseButton1Click:Connect(leftClick) script.Parent.MouseButton2Click:Connect(rightClick)

EDIT: I forgot to mention, I want to make it so that it pops up in everyones screen. Right now, it's in a local script and putting it on a regular script wont work. It works fine, but it only pops up in my screen.

1 answer

✓ Accepted answer

To make this, you will need to know how to use: RemoteEvent

In a LocalScript, we will connect to two events of TextButton

local Event = game.ReplicatedStorage.RemoteEvent -- Change RemoteEvent to the name of the RemoteEvent

script.Parent.MouseButton1Click:Connect(function()
        Event:FireServer(1)
end)

script.Parent.MouseButton2Click:Connect(function()
        Event:FireServer(0)
end)

This will fire the event with one of the arguments: 1, 2.

Now in a script that's in ServerScriptService, add:

local Event = game.ReplicatedStorage.RemoteEvent -- Change RemoteEvent to the name of the RemoteEvent

Event.OnServerEvent:Connect(function(Player, Transparency)
        game.Workspace.Food.Transparency = Transparency
end)

I hope it helped!

4 comments

0

I tested it and it seems it was only client sided for me. I think I did a mistake? Can you please check ?

0

Sure

0

Everything looks working for me. Perhaps you didn't change the script or maybe script isn't a Server Script (Which it isn't possible)

0

I typed something wrong. Not sure what it was, but I just pasted your script and changed it instead of typing it manually

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