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

TextButton working in-studio however, not in game?

Hey, guys so I have a huge problem on my hands right now that I have completely no solution to so I was hoping someone on here can help me out! Here is my problem:

I put a ScreenGui inside of StarterGui then I put FilteringEnabled on Workspace true and then I put a TextButton inside of the ScreenGui then I added a RemoteEvent inside of the TextButton and I added a LocalScript inside of the RemoteEvent so lemme draw the picture right here it looks something like this...

ServerScriptService

 Script

StarterGui

ScreenGui

      TextButton

           RemoteEvent

                LocalScipt

Above is my set up.... The problem is that when I do it in studio it works perfectly fine however, when I do it in-game it does not work for some completely unknown reason...

Here is my ServerScriptService Script:

--SERVER SCRIPT INSIDE OF SERVERSCRIPTSERVICE--

game.Players.PlayerAdded:connect(function(plr)
	if plr then
		local pg = plr:WaitForChild("PlayerGui")
		local sg = pg:WaitForChild("ScreenGui")
		local tb = sg:WaitForChild("TextButton")
		local re = tb:WaitForChild("RemoteEvent")
		tb.MouseButton1Click:connect(function()
			local event = re
			event:FireClient(plr)
		end)
	end
end)

Well now time for my script inside of the Remote Event:

--LOCAL SCRIPT INSIDE OF REMOTE EVENT--

script.Parent.OnClientEvent:connect(function()
	print("Works!")
end)

Thank you so much I'd be eternally greatful to anyone that found out as to what is wrong with this! THANK YOU IN ADVANCE!

~~ KingLoneCat

1 answer

✓ Accepted answer

From what I have seen, my GUIs work with LocalScript in them for doing something. If you try to do something to the server, thats when we need a RemoteEvent

As such, in a localscript inside of the gui you would have this code:

local screengui = script.Parent
local playergui = screengui.Parent
local textbutton = screengui["TextButton"]

textbutton.MouseButton1Down:connect(function()
	print("Works! :D")
end)

Now, if you wish to do something to the game, we will use a RemoteEvent, in this example I will change the part's transparency to 1 of Part in Workspace

There will be a Script in ServerScriptService that receives the event:

local SeEventACreate = Instance.new("RemoteEvent",game.ReplicatedStorage)
SeEventACreate.Name = "ServerEventA"
SeEventA.OnServerEvent:connect(function()
	game.Workspace.Part.Transparency = 1
	print("Works! :D")
end)

There will also be a LocalScript in the ScreenGui

local screengui = script.Parent
local playergui = screengui.Parent
local textbutton = screengui["TextButton"]
local SeEventA = game.ReplicatedStorage:WaitForChild("ServerEventA")

textbutton.MouseButton1Down:connect(function()
	SeEventA:FireServer()
end)

For further help on Remote Events see this ROBLOX wiki page:

http://wiki.roblox.com/index.php?title=RemoteFunction_and_RemoteEvent_Tutorial

Should you still come to trouble, send me a PM on ROBLOX:

https://www.roblox.com/messages/compose?recipientId=18982229

~ Taryo

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