Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

3 comments

0

You can't access PlayerGui/PlayerScripts from the server.

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?

0

Use a remoteevent

1 answer

✓ Accepted answer

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

3 comments

0

Should work if not reply and i'll fix it real fast

2

It still doesn't work. Thank you for the help though!

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

This discussion is preserved as it was. New answers, comments, and votes are closed.