How do I make this work in a global script:
local player=game.Players.LocalPlayer
How do I make this work in a global script:
local player=game.Players.LocalPlayer
You can have a local script make the value of an object value the player
Local Script
--assuming the local script is in starterpack and the objectvalue is under the name of "player" in the workspace
workspace.player.Value = game.Players.LocalPlayer
script:Destroy()
Server Script
--workspace.player.Changed:connect(function(value)
player = value
end
--now you can reference the player using player.
Alternatively, you could have a table that is changed whenever a player joins or leaves.
Server Script
local players = {}
game.Players.PlayerAdded:connect(function(player)
players[player.Name] = player
end)
game.Players.PlayerRemoving:connect(function(player)
players[player.Name] = nil
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.
4 comments
Thanks!
Hey, I just tested it, and It says "global player nil value". Do you know why this is happening?
What's your tree? I.e. where is the serverscript, localscript, and object value?
the object value is under Workspace, the server script is under a model, and the local is in StarterPack