function onMouseClick(player) print('player who clicked is ' .. player.Name) player.PlayerGui.Obtained.Enabled = true player.PlayerScripts.Items.Keys.Value = true wait(5) player.PlayerGui.Obtained.Enabled = false end script.Parent.ClickDetector.MouseClick:connect(onMouseClick)
This script works fine in studio testing but when I start a server it doesn't work? Do I need to put it in a local script?
Ok, I figured it out, thanks for anyone who helped. I just needed a Remote Function to create a KeysObtained Remote Event and a local script within the Gui.
Things you need
1 - A RemoteEvent
In ReplicatedStorage
local rep = game:GetService('ReplicatedStorage') local event = rep:WaitForChildChild('RemoteEvent') function onMouseClick(player) event:FireClient(player) end script.Parent.ClickDetector.MouseClick:connect(onMouseClick)
And second code in a LocalScript
In PlayerGui
local rep = game:GetService('ReplicatedStorage') local event = rep:WaitForChildChild('RemoteEvent') event.OnClientEvent(plr) local player = game.Players.LocalPlayer print('player who clicked is ' .. player.Name) player.PlayerGui.Obtained.Enabled = true player.PlayerScripts.Items.Keys.Value = true wait(5) player.PlayerGui.Obtained.Enabled = false end