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 mention player on a normal script?

So I want to mention a player in a normal script... I can't use localplayer like I used until now cuz Im not using a local script, I would love help thx :)

3 comments

0

In what context do you want to mention a player and when? When a player clicks on a clickdetector? Or when a player walks on a part? There are different ways to approach based on context.

0

I think he just meant defining the local player. When you define it once, you can use it on other functions.

0

ah true.

2 answers

✓ Accepted answer
local plr

game.Players.PlayerAdded:Connect(function(player)
	plr = player
end)

wait(1) -- To wait for the player to add

print(plr.Name)

It sets another variable (plr) to the player that gets defined when the PlayerAdded function runs. If you need any further explanation just ask.

This is a way you can get a player from a server-side script if you have the players character.

local Players = game:GetService("Players")
 
local part = script.Parent

local function onTouched(part)
	local player = Players:GetPlayerFromCharacter(part.Parent) --part.Parent refers to the Character.
	print(player.Name .. " pressed me!")
end

part.Touched:Connect(onTouched)

I don't know what you mean by "mentioning a player". Like, in what context?

Players:GetPlayerFromCharacter()

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