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

script works in offline testing but in game doesn't work?

Asked by 6 years ago
Edited 6 years ago
1function onMouseClick(player)
2print('player who clicked is ' .. player.Name)
3player.PlayerGui.Obtained.Enabled = true
4player.PlayerScripts.Items.Keys.Value = true
5wait(5)
6player.PlayerGui.Obtained.Enabled = false
7end
8 
9script.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.

0
You can't access PlayerGui/PlayerScripts from the server. User#19524 175 — 6y
2
How would I go about doing this then? I have the game set up where theres a folder of items for each player saved in PlayerScripts, how would I access those? titaneagle 0 — 6y
0
Use a remoteevent seith14 206 — 6y

1 answer

Log in to vote
1
Answered by
seith14 206 Moderation Voter
6 years ago
Edited 6 years ago

Things you need 1 - A RemoteEvent In ReplicatedStorage

1local rep = game:GetService('ReplicatedStorage')
2local event = rep:WaitForChildChild('RemoteEvent')
3 
4function onMouseClick(player)
5event:FireClient(player)
6end
7 
8script.Parent.ClickDetector.MouseClick:connect(onMouseClick)

And second code in a LocalScript In PlayerGui

01local rep = game:GetService('ReplicatedStorage')
02local event = rep:WaitForChildChild('RemoteEvent')
03 
04event.OnClientEvent(plr)
05local player = game.Players.LocalPlayer
06print('player who clicked is ' .. player.Name)
07player.PlayerGui.Obtained.Enabled = true
08player.PlayerScripts.Items.Keys.Value = true
09wait(5)
10player.PlayerGui.Obtained.Enabled = false
11end
0
Should work if not reply and i'll fix it real fast seith14 206 — 6y
2
It still doesn't work. Thank you for the help though! titaneagle 0 — 6y
0
It should of worked before but I changed it a little, instead It's using localplayer, make sure it's in a localscript the second code seith14 206 — 6y
Ad

Answer this question