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

Why is this still not running in the game, and working in test mode? (F/E PROBLEM)

Hello, this is a follow up to my earlier question, I've edited the script and been playing around with it all day but still something's wrong. If anyone well versed in filtering enabled could help I would be grateful. This script is for a GUI open/close button that works with Filtering Enabled on. This script is in a local script, it's parent is the textbox acting as the Open/Close button.

local TextBox = game.Players.PlayerName.PlayerGui:WaitForChild("Customizer").CloseTab
TextBox.MouseButton1Down:connect(function()
	game.Workspace.OpenCloseEvent:FreServer()
end)

This is the ServerScript located in ServerScriptStorage, it creates and describes the remote event.

local event = Instance.new("RemoteEvent")
event.Name = "OpenCloseEvent"
event.Parent = game.Workspace
event.OnServerEvent:connect(function()
	local TextBox = game.Players.PlayerName.PlayerGui:WaitForChild("Customizer").CloseTab
	if TextBox.Text == "Open" then
		game.Players.PlayerName.PlayerGui:WaitForChild("Customizer").PositioningFrame.Visible = true
		print('1')
		game.Players.PlayerName.PlayerGui:WaitForChild("Customizer").CloseTab.Text = 'Close'
	else
 		game.Players.PlayerName.PlayerGui:WaitForChild("Customizer").PositioningFrame.Visible = false
		print('2')
		game.Players.PlayerName.PlayerGui:WaitForChild("Customizer").CloseTab.Text = 'Open'
	end
end)

Many thanks to anyone that can assist me

1 answer

✓ Accepted answer

Scripts should not modify anything in a player's PlayerGui.

There is no need for server-client communication to accomplish this. The LocalScript can do all of the work.

You should also not be using anything like game.Players.PlayerName. The OnServerEvent is given the player that fired the event as the first parameter; the LocalScript should be using game.Players.LocalPlayer.

-- LocalScript (no Script needed)

local player = game.Players.LocalPlayer
local customizer = player.PlayerGui:WaitForChild("Customizer")
local closeTab = customizer.CloseTab
local positioningFrame = customizer.CloseTab

closeTab.MouseButton1Down:Connect(function()
	if closeTab.Text == "Open" then
		positioningFrame.Visible = true
		print('1')
		closeTab.Text = 'Close'
	else
		positioningFrame.Visible = false
		print('2')
		closeTab.Text = 'Open'
	end
end)

It generally helps to avoid really long lines like game.Players.PlayerName.PlayerGui:WaitForChild("Customizer") over and over. Save them into variables like I did above!

1 comment

0

Thankyou so much! This is helpful and I'll try it out when I have some time, I'll get back to you if it works.

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