So, I've been experimenting with _G and I think it's broken for a reason: when I first tried to print some object's name, it printed it; I don't know why but it doesn't print that anymore but instead prints 'nil'. I also can't understand why it doesn't work for adding points to a player's leaderstats. Here's my code in the first script:
game.Players.PlayerAdded:Connect(function(player) local LS = Instance.new("Folder", player) LS.Name = "leaderstats" local T = Instance.new("IntValue", LS) T.Name = "Test" _G.Test = T.Value end)
Here's the second:
script.Parent.MouseClick:Connect(function() _G.Test = _G.Test + 25 end)
They both are in different locations: the first one is in the ServerScriptService
, the second is in a part
in the workspace
. Please explain why won't it work.
The problem is that the ServerScriptService won't replicate over to clients, it is exclusively server-side. However, this is only a problem for the clients; if you switch to the server's view everything should be correct. Try moving the first script into Workspace, rather than ServerScriptService.