Index Local Player in script, or any other alternatives

Hi!, I would like to know how can i index the local player in a script, or any other alternatives. So I need some help. :smiley:

Scripts can’t get a LocalPlayer, but you can use PlayerAdded to get a player when they join.

game.Players.PlayerAdded:Connect(function(player)
     print(player.Name .. " has joined the game!")
end)

So actually I’m making a proyectile script, I wanted to index the local player that fired it.

If this is through a remote event get the player from OnServerEvent, remember that the server has no concept of “local player” so it is not correct to refer to a player as a “local player” in the context of server.

1 Like

Yes it’s from a remote event, so your saying I can “index” the “local player” through an argument?

The first arguement that is passed to the remote event is the Player object, you can access it like

local someEvent = game.ReplicatedStorage.someEvent

someEvent.OnServerEvent:Connect(function(player)
  print(player.Name) <-- Should print the player who fired it
end)
1 Like

Yes, it worked !! , thanks @MayorGnarwhal @sjr04 @WaterJamesPlough !

1 Like

Instance, not object.

An instance is a specific representation of an object.
An object is a generic thing while an instance is a single object that has been created in memory.

Usually an instance will have values assigned to it’s properties that differentiates it from other instances of the type of object.

Sources:

  1. oop - What is the difference between an Instance and an Object? - Stack Overflow.
  2. RemoteEvent | Documentation - Roblox Creator Hub
2 Likes

Oh, I learnt the difference properly now. Thanks :slight_smile:

2 Likes