pointFolder isn't a child of Player

There is an error in the output when I test my game, this error is saying that pointFolder (where I store points), isn’t a value of player. Everything is spelled the correctly and “Player” is the play I want. So I don’t understand what is happening.

Script

--variables
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local status = ReplicatedStorage:WaitForChild("Status")
local length = 180
local chosenMap

--loop
while true do
	
	status.Value = "Waiting for players."
	
	repeat wait(1) until game.Players.NumPlayers >= 2
	
	status.Value = "Intermission"
	
	wait(7)
	
	local plrs = {}
	
	local Players = game:GetService("Players")
	
	for i, player in pairs(game.Players:GetPlayers()) do
		if player then
			table.insert(plrs, player)
		end
	end
	
	Players.PlayerRemoving:Connect(function(player)
		table.remove(plrs, player)
	end)
	
	wait(2)
	
	local mapNumber = math.random(1,2)
	
	if mapNumber == 1 then
		
		status.Value = "Freaky Forest Chosen"
		chosenMap = game.Workspace.Map1 
		
	elseif mapNumber == 2 then
		
		status.Value = "Castle Island Chosen!"
		chosenMap = game.Workspace.Map2
		
	end
	
	-- Teleport
	local spawns = chosenMap.Spawns:GetChildren()
	
	for i, player  in pairs(plrs) do
		if player then
			character = player.Character
			
			if character then
				character:FindFirstChild("HumanoidRootPart").CFrame = spawns[1].CFrame
				table.remove(spawns, 1)
				
				local newSword = ServerStorage.Sword:Clone()
				newSword.Parent = player.Backpack
				
				local deadTag = Instance.new("BoolValue")
				deadTag.Name = "deadTag"
				deadTag.Parent = character
			end
		else
				
			if not player then
				table.remove(plrs,i)
			end				
		end
	end
	
	status.Value = "Game has begun!"
	
	Players.PlayerRemoving:Connect(function(player)
		table.remove(plrs, player)
	end) 
	
	wait(3)
	
	for i = length, 0, -1 do
		
	Players.PlayerRemoving:Connect(function(player)
		table.remove(plrs, player)
	end)
		
		for x, player in pairs(plrs) do
			if player then
				character = player.Character
				if not character then
					
				else
					if character:FindFirstChild("deadTag")then
						print(player.Name.."is in the game.")
					else
						table.remove(plrs, x)
					end
				end
			else
				table.remove(plrs, x)
			end
		end
		status.Value = i.." seconds left and "..#plrs.." players left." 
		
		Players.PlayerRemoving:Connect(function(player)
			table.remove(plrs, player)
		end)
		
		if #plrs == 2 then
			status.Value = plrs[1].Name.." and "..plrs[2].Name.." are the last ones left."
			plrs[1].pointFolder.Points.Value = plrs[1].pointFolder.Points.Value + 1
			plrs[2].pointFolder.Points.Value = plrs[2].pointFolder.Points.Value + 1
		end
		
		if #plrs == 1 then
			status.Value = plrs[1].Name.." has won!"
			plrs[1].pointFolder.Points.Value = plrs[1].pointFolder.Points.Value + 2
			break
		elseif #plrs == 0 then
			status.Value = "No one won :("
			break
		elseif i == 0 then
			status.Value = "Time up."
		end
		
		wait(3)
	end
	
	print("End of game.")
	
	for i, player in pairs(game.Players:GetPlayers())do
		character = player.Character
		if not character then
			
		else
			if character:FindFirstChild("deadTag") then
				character.deadTag:Destroy()
			end
			
			if player.Backpack:FindFirstChild("Sword") then
				player.Backpack.Sword:Destroy()
			end
			
			if character:FindFirstChild("Sword") then
				character.Sword:Destroy()
			end			
		end
		player:LoadCharacter()
	end
	status.Value = "Game finished."
	wait(3)
end

The error means that pointFolder is not a child of the given Player object, are you sure pointFolder has been created when you try to access it? I don’t see that it’s been done in this specific script.

It has been done in a DataStore script.

Can you show us the datastore script? or at least the part where you made a leaderstats/points

1 Like
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("DataStore") 

game.Players.PlayerAdded:Connect(function(player)
	
	local pointFolder = Instance.new("Folder")
	pointFolder.Name = "pointFolder"
	pointFolder.Parent = player

	
	local points = Instance.new("IntValue")
	points.Name = "Points"
	points.Parent = pointFolder
	
	player.CharacterAdded:Connect(function(character)
		character.Humanoid.WalkSpeed = 16
		character.Humanoid.Died:Connect(function()
			if character:FindFirstChild("deadTag") then
				character.deadTag:Destroy()
			end
		player:LoadCharacter()
	end)


local playerUserId = "Player_"..player.UserId

--Local Data
local data
local success, errormessage = pcall(function()
	data = DataStore:GetAsync(playerUserId)
end)
	
if success and data then
	points.Value = data[1]
	--Set the data equal to the current value
else
	print("Data not found")
end


game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = "Player_"..player.UserId

local data = {
	player.pointFolder.points.Value;
}
end)

Ok so I just made a similar script, and it worked just fine for me. Can you show us the error in the output (screenshot)?

1 Like

I just realized I found a second error and I think it is causing the other thing to error.

Ah alright. I don’t think that would affect the points not updating for the winners, but update me on any errors in the output

2 Likes

This is the only other error
image
Since there is an error it stop the loop entirely making the whole game unplayable.

Just for clarification, when you say plrs[1].Name, does it show their name?

1 Like

Yes it does.

Ok so maybe instead of doing updating the leaderstats for each player on a seperate line, you can do this instead:

for _, p in pairs(plrs) do
    local points = p.pointFolder.Points.Value
    points.Value = points.Value + 1 --or 2 if #plrs is 1
end
1 Like

I don’t think that will solve anything. I am pretty sure it has to do with the data store.

Is pointFolder the name of the folder?

1 Like

Yes it is.

What is exactly the part that errors?

Use:

local data = {
	player:WaitForChild"pointFolder".points.Value;
}
end)

Also game.Players.PlayerAdded does’nt have an end).

This part!

The second error that you got means that you forgot to close a function. (With “end”)
Let me know if it worked.

1 Like

I am loading up studio rn!

I added an end where I thought it should be but it didn’t work.

Nvm! I found where the mistake was made :smiley: I think it should work now!