Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-2

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

Asked by 9 years ago

How do I make this work in a global script:

local player=game.Players.LocalPlayer

1 answer

Log in to vote
0
Answered by 9 years ago

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)

0
Thanks! NAWESOME14 40 — 9y
0
Hey, I just tested it, and It says "global player nil value". Do you know why this is happening? NAWESOME14 40 — 9y
0
What's your tree? I.e. where is the serverscript, localscript, and object value? aquathorn321 858 — 9y
0
the object value is under Workspace, the server script is under a model, and the local is in StarterPack NAWESOME14 40 — 9y
Ad

Answer this question