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

Why will this work in studio test mode and NOT in the game itself?

Hello, I've been working to enable filtering on my game as it was recently shut down by roblox-demanding that we do so. I've encountered a few problems, the main one being all of my fixes do not actually work in game. These all work in studio test mode. This is the script that fires the remote event it is located in ServerScriptService

local TextBox = game.Players.LocalPlayer.PlayerGui.Customizer.CloseTab
TextBox.MouseButton1Click:connect(function()
	if TextBox.Text == 'Open' then
		print("Firing")
		game.Workspace.OpenEvent:FireServer()
		print("Fired")
	else
 		game.Workspace.CloseEvent:FireServer()
	end
end)

This is the script ALSO located in ServerScriptService that creates and describes the event

local event = Instance.new("RemoteEvent")
event.Name = "OpenEvent"
event.Parent = game.Workspace
event.OnServerEvent:connect(function()
	game.Players.LocalPlayer.PlayerGui.Customizer.PositioningFrame.Visible = true
	print('1')
	game.Players.LocalPlayer.PlayerGui.Customizer.CloseTab.Text = 'Close'
end)

The close event is very similar and is located also in ServerScriptStorage.

Many thanks

2 answers

You need to use WaitForChilds, I will fix the script and at the same time explain;

Script 1;

local TextBox = game.Players.LocalPlayer.PlayerGui:WaitForChild("Customizer").CloseTab -- Added WaitForChild so you can wait for Customizer to load in
TextBox.MouseButton1Down:connect(function() -- Changed to 1Down
    if TextBox.Text == 'Open' then
        print("Firing")
        game.Workspace.OpenEvent:FireServer()
        print("Fired")
    else
        game.Workspace.CloseEvent:FireServer()
    end
end)

Now for script 2;

local event = Instance.new("RemoteEvent")
event.Name = "OpenEvent"
event.Parent = game.Workspace
event.OnServerEvent:connect(function()
    game.Players.LocalPlayer.PlayerGui:WaitForChild("Customizer").PositioningFrame.Visible = true -- Added wait for child
    print('1')
    game.Players.LocalPlayer.PlayerGui:WaitForChild("Customizer").CloseTab.Text = 'Close' --Added wait for child
end)
-- I highly suggest you make a variable because you used it more then once.

7 comments

0

Thanks very much for explaining this, I'll give it a try and come back to you

0

No problem

0

This still doesn't want to work, will placing script1 under starterplayerscripts make any difference?  edit: it works in studio again but not in the main game

0

hold on

0

is the textbutton visible right when you join?

0

Try using a WaitForChild for your humanoid and then execute the script so you are fully certain it loads when the character of a player has loaded

0

The textbutton is visible and it detects that it's being clicked. It just does nothing

FireServer() Can be only used in LocalScript. I assume that you used it in ServerScript because of it's parent (SeverScriptService) if not then let me remind you that LocalScript will not work in ServerScriptService.

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