Folder in my player but game doesnt recognize it's there?

So I have yet another problem: there is a folder in my player called “Values”, but the game does not recognize that it is there, and gives me an error. This completely breaks my game, so any help would be appreciated! If you need more info, just let me know.

The error output is: "Values is not a valid member of Player “Players.Noobzilla1207”.

Here is the part of the Script with the problem:

task.spawn(function()
	while task.wait(1) do
		if player.Values.SentTo.Value ~= nil then
			local dmg = 20
			player.Values.SentTo.Value.Health.Value = math.max(player.Values.SentTo.Value.Health.Value - dmg, 0)
			if player.Values.SentTo.Value.Health.Value == 0 then
				remotes.StopDamaging:FireServer()
				destroyDrop(player.Values.SentTo.Value)
			end
		end
	end
end)

Here is the script that gives the value to the player (its kinda long sorry):

local RunService = game:GetService("RunService")
local PlayersService = game:GetService("Players")

local MF = workspace.MainFolder_Workspace
local PPs = MF.PlayerPets
local drops = MF.Drops
local DataStoreService = game:GetService("DataStoreService")
local petsData = DataStoreService:GetDataStore("-petInventoryE")

-- // 

game:GetService("Players").PlayerAdded:Connect(function(PlayerWhoAdded)
	local backpackFolder = Instance.new("Folder")
	backpackFolder.Name = "OwnedPets"
	backpackFolder.Parent = PlayerWhoAdded
	
	local PetsFolder = Instance.new("Folder")
	PetsFolder.Name = PlayerWhoAdded.Name
	PetsFolder.Parent = PPs
	

	for _, v in pairs(script.PlayerData:GetChildren()) do
		v:Clone().Parent = PlayerWhoAdded
	
	local CS = PlayerWhoAdded:WaitForChild("ActionValues"):WaitForChild('CurrentInventorySpace') -- Current Pet Storage
	
	local UserId = PlayerWhoAdded.UserId
	local success, data = pcall(petsData.GetAsync, petsData, UserId)

	if success and data then
		for i, OldData in pairs(data) do
			local n = Instance.new('StringValue')
			n.Name = OldData
			n.Parent = backpackFolder
			n.Value = ""
			
			CS.Value += 1 -- Adds An Inv Slot for Each Pet
		end
		local PlayerGUI = PlayerWhoAdded:WaitForChild("PlayerGui")
		
		wait(2)
		game:GetService("ReplicatedStorage").ServerEvents.reloadData:FireClient(PlayerWhoAdded,"petsLoading")
		end
	end
end)

game:GetService("Players").PlayerRemoving:Connect(function(Player)
	local DataToSave = {}
	local UserId = Player.UserId

	for _,EachValue in pairs(Player.OwnedPets:GetChildren()) do
		table.insert(DataToSave,EachValue.Name)
	end

	local Success,errorMessage = pcall(petsData.UpdateAsync, petsData, UserId, function()
		return DataToSave
	end)

	if not Success then
		warn("Pets Data Could Be LOST! - " .. errorMessage)
end
	if PPs:FindFirstChild(Player.Name) then
		PPs:FindFirstChild(Player.Name):Destroy()
	end
end)


game:BindToClose(function()

	if not RunService:IsStudio() then
		for _,LocalPlayer in pairs(PlayersService) do

			local DataToSave = {}
			local UserId = LocalPlayer.UserId

			for _,EachValue in pairs(LocalPlayer.OwnedPets:GetChildren()) do
				table.insert(DataToSave,EachValue.Name)
			end

			local Success,errorMessage = pcall(petsData.UpdateAsync, petsData, UserId, function()
				return DataToSave
			end)

			if not Success then
				warn("Pets Data Could Be LOST! - " .. errorMessage)
			end
		end
	end
end)

game.ReplicatedStorage.Remotes.PurchaseDoor.OnServerInvoke = function(player, door)
	local serverDoor = workspace.MainFolder_Workspace.Doors:FindFirstChild(door.Name)

	if serverDoor then
		if player.leaderstats.ECoins.Value >= serverDoor.Price.Value then
			if not player.Areas:FindFirstChild(serverDoor.Name) then
				player.leaderstats.ECoins.Value -= serverDoor.Price.Value
				local doorVal = Instance.new("StringValue")
				doorVal.Name = serverDoor.Name
				doorVal.Parent = serverDoor.Parent
				return true
			end
		else
			return false
		end
	end
end

game.ReplicatedStorage.Remotes.StopDamaging.OnServerEvent:Connect(function(player)
	player.Values.SentTo.Value = nil
	local CPPs = PPs[player.Name]
	if #CPPs:GetChildren() > 0 then
		local pet = CPPs:FindFirstChildOfClass("Model")
		pet.Attack.Value = nil
	end
end)

for _, drop in pairs(drops:GetDescendants()) do
	if drop:IsA("Model") then
		drop.Health.Value = drop.MaxHealth.Value
		drop.ClickDetector.MouseClick:Connect(function(player)
			local CPPs = PPs[player.Name]
			if #CPPs:GetChildren() > 0 then
				local pet = CPPs:FindFirstChildOfClass("Model")
				if player.Values.SentTo.Value == nil then
					player.Values.SentTo.Value = drop
					pet.Attack.Value = player.Values.SentTo.Value
				elseif player.Values.SentTo.Value == drop then
					player.Values.SentTo.Value = nil
					pet.Attack.Value = player.Values.SentTo.Value
				elseif player.Values.SentTo.Value ~= nil and player.Values.SentTo.Value ~= drop then
					player.Values.SentTo.Value = drop
					pet.Attack.Value = player.Values.SentTo.Value
				end
			end
		end)
	end
end

for _, door in pairs(workspace.MainFolder_Workspace.Doors:GetChildren()) do
	door.ProximityPart.ProximityPrompt.Triggered:Connect(function(player)
		if not player.Areas:FindFirstChild(door.Name) then
			game.ReplicatedStorage.Remotes.PromptPurchaseDoor:FireClient(player, door)
		end
	end)
end

And lastly, here is proof showing that the “Values” folder is in my Player:
proof

Sorry for the long reading!

You can replace occurrences of player with game.Players.LocalPlayer if you’re testing in a LocalScript or use game.Players:GetPlayerFromCharacter(character) to get the player object from the character

i already have the player variable set as “player = game.Players.LocalPlayer” in the Local Script (the one presenting the error)

Oouh babes then the issue might be related to the timing of when the “Values” folder is created and when the script is accessing it

ohhhhhh how could i have missed that lol. Thanks!

wait nvm i just realized they are two seperate scripts: the local script is accessing the Values folder and the script is the one creating it

Ah! Then you need to ensure that the folder is created and accessible before the local script tries to access it, to synchronize the creation of the folder and the script that accesses it, you can use a RemoteEvent to signal when the folder has been created

so how would i go about doing that? would i fire the remote event in the Local Script? etc.

Put this in the script that creates the folder (ServerScript or LocalScript):

local player = game.Players.Noobzilla1207 -- Replace this with the actual player object
local valuesFolder = Instance.new("Folder")
valuesFolder.Name = "Values"
valuesFolder.Parent = player
script.Parent:FireClient(player, valuesFolder)

And put this in the local script where you need to access the folder:

local player = game.Players.LocalPlayer

script.Parent.OnClientEvent:Connect(function(folder)
    local valuesFolder = folder 
    
    task.spawn(function()
        while wait(1) do
            if valuesFolder.SentTo.Value ~= nil then
                local dmg = 20
                valuesFolder.SentTo.Value.Health.Value = math.max(valuesFolder.SentTo.Value.Health.Value - dmg, 0)
                if valuesFolder.SentTo.Value.Health.Value == 0 then
                    remotes.StopDamaging:FireServer()
                    destroyDrop(valuesFolder.SentTo.Value)
                end
            end
        end
    end)
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.