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

Player is not a valid member of Workspace..?

So I've been working on attempting to restore and fix BuildIntoGames' Guest Defense 1. So far, I've gotten most features functioning, but I've encountered this one error and I have no clue how to get past it. I've tried everything, but I'm fried at this point. I feel like the answer is really obvious, but I'm just not looking there.

The error that comes up is "Player is not a valid member of Workspace"

Anyways, here's the code. The error comes at line 3.

while true do
wait(3)
player = game.Players:findFirstChild("" .. game.Workspace.Player)
level = player.Level
script.Parent.Level.Text = "Level : " .. level.Value
end

Thanks a ton, I'd really appreciate the help.

5 comments

1

Do you ever have anything named "Player" exactly directly under workspace? If not, that's exactly what the error is saying.

0

Using game.Workspace.Player would work fine in other scripts, but it only seems to be this one that doesn't want to work

0

is it a local script or a server script? that might be a problem.

0

It's in ReplicatedStorage

0

Not a local script, just your normal script.

2 answers

✓ Accepted answer

The way you did this is very unprofessional. Not to worry, I have fixed up the code for you!

game.Players.PlayerAdded:connect(function(player)
	level = player:WaitForChild'Level'
	level.Changed:connect(function()
		script.Parent.Level.Text = "Level: "..level.Value
	end)
end)

Basically what this script does is, when a player joins the game, it waits for the "level" value, and whenever the "level" value is changed, it changes the script.Parent.Level.Text to the newest level.

1 comment

0

Thank you, I knew that my code was sloppy, but this will work a lot better.

Figured it out myself. Adding this code ABOVE lines of code that called for my Player variables and such seemed to fix the issue (as well as setting my Player variable to this)

if workspace:FindFirstChild("Player") then

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