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

My GUI script, which is activated by a click detector, works in game but not in studio?

I have tried creating an object that would open a GUI. I put in a click detector and a script. The script works flawlessly in studio, but not in-game. I have tried making the script a local script, but it still doesn't work. This is the script.

script.Parent.MouseClick:connect(function(player)

player.PlayerGui.TING.TANG.Visible = not player.PlayerGui.TING.TANG.Visible
	
end)

1 answer

This is because on line 1, you’re using deprecated code. Change :connect to :Connect.

This doesn’t work because your game is FE enabled, which disallows the server to change the Gui (it shouldn’t be anyways!). Instead, use a RemoteEvent and make the gui visible.

-- LocalScript inside TANG

local rep = game:GetService"ReplicatedStorage"
local remote = rep:WaitForChild"ShowGUI"

remote.OnClientEvent:Connect(function()
    script.Parent.Visible = not script.Parent.Visible
end)

ServerScript inside your click detector:

-- Server script, in your click detector

local remote = Instance.new'RemoteEvent'
remote.Name = 'ShowGUI'
remote.Parent = game:GetService('ReplicatedStorage')
local storage = "ReplicatedStorage"

script.Parent.MouseClick:Connect(function(plr) -- Connect not connect
    game:GetService(storage):WaitForChild('ShowGUI'):FireClient(plr)
end)

2 comments

0

Hey, hey. Hold on. The RemoteEvent should be created only once, because if LocalScript makes it then there will be 1 remoteevent per every player which was in game. Please change that, because it's important note. Script won't work when there is more than 1 player.

0

true^ let me fix it

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