Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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

Log in to vote
-1
Answered by 6 years ago
Edited 6 years ago

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)
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. Etheroit 178 — 6y
0
true^ let me fix it User#19524 175 — 6y
Ad

Answer this question