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

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

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

script.Parent.Touched:connect(function(player)
z = player.Parent:GetPlayerFromCharacter()
    print(z.ClassName)
end)


:GetPlayerFromCharacter() Helps.

+1 if helped.

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)

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)

1 comment

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.

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