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

Help with calling on a player?

Okay so I need this script to find the players name.

Here is what I have:

local function Open(msg)
	Player = --This is where I need help
	if Player.Name == "AnonymousPain" then
	if msg == "Enable Lobby" then
	script.Parent.CFrame = CFrame.new(0, .1, 0)
	wait(.1)
	script.Parent.CFrame = CFrame.new(0, .1, 0)
	repeat until
	script.Parent.Position == Vector3(20.715, 45, 373.685)
	
	
end		
 end
   end

If you can help thanks.

2 answers

✓ Accepted answer

To find the player, if you are using chat commands, use the PlayerAdded trigger.

In case you didn't guess, the PlayerAdded trigger is fired when a player enters a server.

game.Players.PlayerAdded:connect(function(player)
--Code stuffs
end)

So in your case, you would put your function inside this code.

function Open(msg, player)--Local functions don't make sense
    Player = player
    if Player.Name == "AnonymousPain" then
    if msg == "Enable Lobby" then
    script.Parent.CFrame = CFrame.new(0, .1, 0)
    wait(.1)
    script.Parent.CFrame = CFrame.new(0, .1, 0)
    repeat until
    script.Parent.Position == Vector3(20.715, 45, 373.685)


end     
 end
   end
game.Players.PlayerAdded:connect(function(player)
	Open("Put your message here", player)
end)

I didn't put how to detect the message since you said you simply needed to detect the player.

Well it really depends.

Solution 1:

If the script is a local script you can do

local player = game.Players.LocalPlayer

Solution 2:

If the script is in a GUI you can do it by seeing how many parents there are until StarterGui and then adding one more Parent. i.e. Let's say there's 3 parents we would do

local player = script.Parent.Parent.Parent.Parent

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