1 | function onMouseClick(player) |
2 | print ( 'player who clicked is ' .. player.Name) |
3 | player.PlayerGui.Obtained.Enabled = true |
4 | player.PlayerScripts.Items.Keys.Value = true |
5 | wait( 5 ) |
6 | player.PlayerGui.Obtained.Enabled = false |
7 | end |
8 |
9 | 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
1 | local rep = game:GetService( 'ReplicatedStorage' ) |
2 | local event = rep:WaitForChildChild( 'RemoteEvent' ) |
3 |
4 | function onMouseClick(player) |
5 | event:FireClient(player) |
6 | end |
7 |
8 | script.Parent.ClickDetector.MouseClick:connect(onMouseClick) |
And second code in a LocalScript
In PlayerGui
01 | local rep = game:GetService( 'ReplicatedStorage' ) |
02 | local event = rep:WaitForChildChild( 'RemoteEvent' ) |
03 |
04 | event.OnClientEvent(plr) |
05 | local player = game.Players.LocalPlayer |
06 | print ( 'player who clicked is ' .. player.Name) |
07 | player.PlayerGui.Obtained.Enabled = true |
08 | player.PlayerScripts.Items.Keys.Value = true |
09 | wait( 5 ) |
10 | player.PlayerGui.Obtained.Enabled = false |
11 | end |