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

Is there a way of knowing the local player in a normal script?

Hello people, i think i have been bugging the forums with my begginer issues, but there is the deal:

I have a Filtering Enabled game, and after watching the wiki and seeing a alvinbloxx video, i learned how to use clickdetectors in filtering enabled, and how remoteEvents work.

The thing is, inside a RemoteEvent i used a script that is this:

game.Workspace.GivePizzaEvent.OnServerEvent:Connect(function()
game.ReplicatedStorage["Pizza"]:Clone().Parent = game.Players.LocalPlayer.Backpack
end)

As us know, "LocalPlayer" cannot be used inside a normal script, resulting in a "nil"

However, i need us to tell me how can i detect a localplayer with a normal script, so i can give that item to the player.

Not only that, but i have a gamepass to give fireworks, that executes the same command.

3 comments

0

When you do :FireServer() the player gets sent over as a default arg

0

um... what you mean with "default arg"?, can you tell me more?

0

By default, fireserver’s first argument is the player.

1 answer

✓ Accepted answer

Simply do this

game.Workspace.GivePizzaEvent.OnServerEvent:Connect(function(player)
game.ReplicatedStorage["Pizza"]:Clone().Parent = game.Players[player.Name].Backpack
end)

Should work.

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