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

Why is my Player not a valid member of workspace?

Asked by 7 years ago
character = game.Workspace.Player
player = game.Players:GetPlayerFromCharacter(character)
torso = character:FindFirstChild("Torso") or character:FindFirstChild("UpperTorso")

It tells me that Player is not a valid member of Workspace. I feel like its something simple that Im missing here....

Please help!

3 answers

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
7 years ago

The dot (.) tries to find the child of an object by name. Your script errors because there is nothing named "Player" inside workspace.

There are character models, but those are named things like "Perci1", "Eagle_RG", "bob123", etc. It's just your username. There is nothing named "Player".



Your specific solution depends on your specific situation. For example, is this a local script? Is this for a touched event? It this when people join the game? Each of these has different solutions, so I would need to know what exactly you want to happen before I can help further.

0
@Percil Thanks! That is exactly the solution I am searching for!! This is a Regular script inside of a model. The model is a NPC and I am trying to assign the "Torso" or "UpperTorso" 's Vector3 to the target. I can target any other "part" in the workspace but not the player. Eagle_RG 2 — 7y
0
So in that case you have to decide who the "target" is. For example, is it the player closest to the model? Perci1 4988 — 7y
0
Ahhhhh!!! Yes, sir/ma'am that is exactly right! It should be the player closest to the model!! Do you have time to post a script or a link to a situation that does that? Eagle_RG 2 — 7y
0
Loop through all the players, then use http://wiki.roblox.com/index.php?title=API:Class/Player/DistanceFromCharacter that to find which one is the closest. Perci1 4988 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

From what I've seen, you're trying to get the players character model:

for i, player in pairs (game.Players:GetChildren()) do
    local character = player.Character
    torso = character:FindFirstChild("Torso") or character:FindFirstChild("UpperTorso")
end)

I'm not sure what you're trying to do exactly as your question is very vague. The script I just made will loop through the players, get each and every one of their torso's, and then you can apply the changes you want(I'm assuming that's why you want this) -- Anyways my guess of your intentions may be off, but you got an error for searching "player" under workspace. The name "Player" won't be under workspace, look for the player under the players folder and then link it to their character.

0
It doesn't get every player's torso; it sets the same variable to each torso every iteration, and the last iteration will be the torso returned. TheeDeathCaster 2368 — 7y
Log in to vote
-1
Answered by 7 years ago

Try this:

local player = game.Players.LocalPlayer
0
error: Torso is not a member of Player Eagle_RG 2 — 7y
0
You need to get the Character. So you would do local torso = player.Character.Torso -- This only works in Local Scripts!! AstrealDev 728 — 7y
0
@mccrafter1212 There's still problems either way. TheeDeathCaster 2368 — 7y

Answer this question