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

Help with calling on a player?

Asked by
F_lipe 135
10 years ago

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

Log in to vote
0
Answered by 10 years ago

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.

Ad
Log in to vote
0
Answered by 10 years ago

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

Answer this question