How can I make it so if a player clicks a GUI button the whole server sees the function and not only who has clicked it?

so I’m going to have a Award ceremony for my community.
I made a TextButton and a TextBox that only certain people have access to, to type in the screen.

The script works fine but the problem is, the text on the screen is seen by only who is typing in the TextBox.
there is no way to make a button click script by a normal server script, only by a LocalScript.
I want the button to show the text on the screen for all players, not just me, but I don’t know how to do it, that’s a problem, support is appreciated.

Here’s the simple script I’ve made.

local button = script.Parent

local text = workspace.Screen.ScreenItself.Awards.AwardsText -- SurfaceGui - TextLabel

button.MouseButton1Click:Connect(function()

local box = script.Parent.TextBox

text.Text = box.Text

end)

And I’ve also tried making variables without the “local” keyword, doesn’t change…

image

1 Like

You are changing the box on the client’s side. Try using remote events to change it for the whole server.

I’m not an expert on scripting, I do not understand remote events yet and all these things, I start from a bit.

You need to use remote events in order to do this, I can explain it if you want.

Alright that sounds good, that’d be nice if you can explain for me.

This can be achieved by using something called a RemoteEvent in order to allow the client to do things that perform actions on the sever. I have included a script below that would work in your case.

-- Make this a LocalScript and keep it where you have it right now.
local button = script.Parent

button.MouseButton1Click:Connect(function()
    local box = script.Parent.TextBox
    local remoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent")

    remoteEvent:FireServer(box.Text)
end)

Then, you will go to a server-sided script and detect when the RemoteEvent is fired, and perform an action. Another example below.

-- Make this a normal script
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr,msg) -- first argument is always player, therefore we need to add "msg" after it. 
    game.Workspace.Screen.ScreenItself.Awards.AwardsText = msg
end)
4 Likes
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr,msg) -- first argument is always player, therefore we need to add "msg" after it. 
    game.Workspace.Screen.ScreenItself.Awards.AwardsText = msg
end)

where would i put that at?

In a normal script, I recommend you put it in ServerScriptService.

1 Like

I’m trying this right now, thank you, I’m testing if it works, are there more ways to do this stuff? because it’s too complicated for me, I’ve never touched RemoteEvents and additional stuff like that…

Without a decent knowledge of scripting, I can understand why this is challenging and somewhat difficult to understand. RemoteEvents are extremely useful things and they are actually probably the easiest way to do stuff like this in most cases. At first, I appreciate that they may seem complicated, but there are many tutorials on YouTube and a detailed Developer Hub article on RemoteEvents and RemoteFunctions, which I recommend you take a look at to find out a bit more.

2 Likes

Thank you so much! I’m going to learn this stuff.
Seems to be working perfectly!

1 Like

Can I ask you another question related to something like this in DMs? because i don’t want it to be marked as a spam since I post here everyday…

Feel free to send me a message on the DevForum and I’ll get back to you as soon as I can.

1 Like