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

Backpack is not valid member of player [WaitForChild() doesnt work) Why?

GAME IS SINGEPLAYER So, I have been using StringValues to know if a player has passed a certain point at the game. Every player has a string value in the backpack that is called Status. When the intro is done, the Status changes from Intro to Playing. When the players status = Playing, the timer is supposed to start. But, it says that Backpack is not valid member of player. Here is the script:

game.Players.PlayerAdded:Connect(function(player)
	local backpack = player:WaitForChild("Backpack")
	if backpack.Status.Value == "Playing" then
for hintTime = 120,1,-1 do
		
		if hintTime >= 60 then
			hint.Text = ("Time left: 2 min " .."("..(hintTime).. " seconds)")
			player.Backpack.Time.Value = 120 - hintTime
			player.leaderstats.Time.Value = 120 - hintTime
			
			elseif
			hintTime >= 0 then
			hint.Text = ("Last minute! " .."("..(hintTime).. " seconds)")
			player.Backpack.Time.Value = 120 - hintTime
			player.leaderstats.Time.Value = 120 - hintTime
		end
		
		wait(1)
 		if player.Backpack.Status.Value == "Win" then
			break
			
		end
	end
	
	end
	
	if player.Backpack.Status.Value == "Win" then
		local playerTime = player.Backpack.Time.Value 
		hint.Text = ("Congratulations " .. player.Name)
		wait(3)
		player.Character.Remover:remove()
		hint.Parent = nil
		msg.Parent = game.Workspace
		msg.Text = "YOU WON!"
		wait(3)
		hint.Parent = game.Workspace
		msg.Parent = nil
		hint.Text = ("You finished this game in " .. playerTime .. " seconds")
		wait(3)
		
		if playerTime >= 30 then
			hint.Text = "Your rank: Legend"
		elseif playerTime >= 60 then
			hint.Text = "Your rank: Expert"
		elseif 	playerTime >= 90  then
		hint.Text = "Your rank: Rookie" 
		elseif playerTime >= 110 then
			hint.Text = "Your rank: Beginner"
		else
			hint.Text = "404 RANK_REQUEST_ERROR"
		end
		wait(2)
		hint.Parent = nil
		wait(2)
		msg.Parent = nil
		hint.Parent = game.Workspace
		hint.Text = "Hope you liked the game"
		wait(2)
		hint.Text = "Feel free to run around the map!"
		wait(2)
		hint.Text = "Press R to restart game!"
		wait(3)
		hint.Text = "Game made by Oficcer_F"
		wait(3)
		hint.Text = "Press R to restart game" 
		msg.Text = "This game was made by Oficcer_F"
		wait(3)
		msg.Parent = nil
	else
		
		
	
	hint.Text = "Time is out"
	player.Backpack.Status.Value = "Lost"
	
	wait(3)
	hint.Text = "Sadly " ..  player.Name .. " you lost."
	wait(2)
	hint.Text = "You weren't fast enough!"
	wait(3)
	hint.Text = "You will now restart"
	wait(3)
	hint.Parent = nil
	msg.Parent = game.Workspace
	msg.Text = "This game was made by Oficcer_F"
	wait(1)
	game:GetService('TeleportService'):Teleport(2153198540, player)
	end
	end)	

THAT IS NOT THE WHOLE SCRIPT

Why doesn't this work?

I HAVE TRIED WaitForChild and wait() etc. I have tried literally everything. When I tried WaitForChild("Backpack") the script didn't even start. It just ignored the whole script. Please help! I am due to update the game, and people have been craving this update!

Output: Backpack is not a valid member of Player

1 answer

Try this and let me know how it works.

game.Players.PlayerAdded:connect(function(player)
	local backpack = player:WaitForChild("Backpack")
	if backpack.Status.Value == "Playing" then
		for hintTime = 120,1,-1 do
       		if hintTime >= 60 then
           		hint.Text = ("Time left: 2 min " .."("..(hintTime).. " seconds)")
            	backpack.Time.Value = 120 - hintTime
            	player.leaderstats.Time.Value = 120 - hintTime
            elseif
          		hintTime >= 0 then
            	hint.Text = ("Last minute! " .."("..(hintTime).. " seconds)")
           		backpack.Time.Value = 120 - hintTime
            	player.leaderstats.Time.Value = 120 - hintTime
        	end
       	 	wait(1)
        	if player.Backpack.Status.Value == "Win" then
            	break
        	end
    	end
    end
end

2 comments

0

Hey, it did not work. First I got a warning; Infinite yield possible on 'Players.Oficcer_F:WaitForChild("Backpack")'. Then it just skipped the first if statement (the one with the timer and everything) and went to the lines under (which I haven't posted) and then skipped all the if statements until, the script came that comes when you loose. I dont understand anymore!

0

I shared the whole script. It seems like it just skip's until the 'else' statement at line 69. I really don't understand I used that method often before. Suddenly it doesn't work!

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