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

How does one find the Player in "Players" without using a local script?

Asked by
Xduel 211 Moderation Voter
10 years ago

So for this basic example, I am trying to print out the Players ClassName.

script.Parent.Touched:connect(function(player)
    print(game.Players.player.ClassName)
end)

From what I believe this script should print "Player", but instead I get the Error from the Output " player is not a valid member of Players". So how would I go about locating the Player in "Players" through a regular script? Answers appreciated, Thank You.

~ Xduel

3 answers

Log in to vote
3
Answered by
HexC3D 830 Moderation Voter
10 years ago
script.Parent.Touched:connect(function(player)
z = player.Parent:GetPlayerFromCharacter()
    print(z.ClassName)
end)


:GetPlayerFromCharacter() Helps.

+1 if helped.

Ad
Log in to vote
2
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
10 years ago
script.Parent.Touched:connect(function(hit) --It was hit by a part...
    possiblename = hit.Parent.Name --So we can find if the hitting part is a player or not.
    if game.Player:FindFirstChild(possiblename) then
        --I guess the name is possible.
        player = game.Player:FindFirstChild(possiblename) --Do what you like to the guy.
    end
end)
Log in to vote
2
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

The top 2 people were on the right track, but didn't complete theirs.

script.Parent.Touched:connect(function(hit)
if hit.Parent and game.Players:GetPlayerFromCharacter(hit.Parent) then
z =game.Players:GetPlayerFromCharacter(hit.Parent)
    print(z.ClassName) -- I have a problem with this. Is this a leaderstat? Because it's not a direct child of player. Or is it?
end)
0
So I tried expanding upon this with adding a KeyDown event, in which when the player is on the part and presses a certain key, an event will happen. I got a script that worked in Play Solo, but not Start Server. Xduel 211 — 10y

Answer this question