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 5 years ago
Edited 5 years ago
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.

0
You can't access PlayerGui/PlayerScripts from the server. User#19524 175 — 5y
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 — 5y
0
Use a remoteevent seith14 206 — 5y

1 answer

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

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
0
Should work if not reply and i'll fix it real fast seith14 206 — 5y
2
It still doesn't work. Thank you for the help though! titaneagle 0 — 5y
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 — 5y
Ad

Answer this question