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

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

Asked by 2 years ago
Edited 2 years ago

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

Log in to vote
0
Answered by
SuperPuiu 497 Moderation Voter
1 year ago
Edited 1 year ago

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!

0
I tested it and it seems it was only client sided for me. I think I did a mistake? Can you please check ? EricAndTheWell 11 — 1y
0
Sure SuperPuiu 497 — 1y
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) SuperPuiu 497 — 1y
0
I typed something wrong. Not sure what it was, but I just pasted your script and changed it instead of typing it manually EricAndTheWell 11 — 1y
Ad

Answer this question