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

SurfaceGUI Not selecting isn't selected. How do I fix?

Hello I have a surface gui that I'm trying to make activate a screengui with custom text to everyone on the server.

I have this so far

function leftClick()
game.StarterGui.EASGui.Frame.ALERT.Text = script.script.Parent.Parent.TextBox.Text 
		script.Parent.Parent.TextBox.Text = ""
		wait(3)
game.StarterGui.EASGui.Frame.Sound.Playing = true
game.StarterGui.EASGui.Enabled = true
wait(30)
game.StarterGui.EASGui.Enabled = false

end

script.Parent.MouseButton1Click:Connect(leftClick)

for the localscript under my textbutton

BTW: Keep in mind that I'm trying to activate the GUI for the ENTIRE server.

1 answer

✓ Accepted answer

To begin, you can't use a LocalScript to change everyone's screen without using a RemoteEvent.

Second, if you change "StarterGui" it won't have any effect, it has to be the PlayerGui, which is a child of each individual player.


To start, put a RemoteEvent in ReplicatedStorage and name it "AlertEvent".

Next, inside your button put a LocalScript and write this.

local event = game:GetService("ReplicatedStorage"):WaitForChild("AlertEvent")

script.Parent.MouseButton1Click:Connect(function()
	local textToSend = script.Parent.Parent.Parent.TextBox
	event:FireServer(textToSend.Text)
end)

This will send arguments to the server, where we will change everyones screen, the first argument will always be the player firing the event, and then any arguments afterwards. For this example, our only argument will be the text that we want to alert.

After that, put a ServerScript inside of ServerScriptService and write this.

local event = game:GetService("ReplicatedStorage"):WaitForChild("AlertEvent")

event.OnServerEvent:Connect(function(plr,text)
	for _,player in pairs(game:GetService("Players"):GetChildren()) do
		player:WaitForChild("PlayerGui"):FindFirstChild("EASGui").Frame.ALERT.Text = text
		wait(3)
		player:WaitForChild("PlayerGui"):FindFirstChild("EASGui").Frame.Sound:Play()
		player:WaitForChild("PlayerGui"):FindFirstChild("EASGui").Enabled = true
		wait(30)
		player:WaitForChild("PlayerGui"):FindFirstChild("EASGui").Enabled = false
	end
end)

This will receive the player who fired the event, and the text we want to change. It will also loop through every player's gui and change the text, play the sound, make it visible, wait 30 seconds, and then not make it visible.

Hope this helped!

If this worked for you, let me know by selecting this as the answer!

If it didn't work, comment down below what went wrong and I'll try to help.

5 comments

0

Well, I forgot to say this in my original question but my textbox doesn't select when I try to type in it. It's not selecting when I click it. Text Editable is enabled

0

Is it a TextBox or a TextButton? If it's a TextButton, that's the problem. If it's a TextBox, try re-inserting it into the previous place.

0

Okay.

0

Actually, I don't need this GUI anymore anyways. Thanks for you help.

0

No problem!

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