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

How do I identify a certain player by using a global script?

How do I make this work in a global script:

local player=game.Players.LocalPlayer

1 answer

✓ Accepted answer

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)

4 comments

0

Thanks!

0

Hey, I just tested it, and It says "global player nil value". Do you know why this is happening?

0

What's your tree? I.e. where is the serverscript, localscript, and object value?

0

the object value is under Workspace, the server script is under a model, and the local is in StarterPack

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