Script not working and not displaying any error

So I was making a system using Data Store, it checks wich value is = “1” and it searchs the value’s name into a ReplicatedStorage folder but it isn’t working and not displaying whats wrong (I checked in the Player if the folder with the values was in there and it was with the value = “1” and the value is changed at Server Side in another place but still didn’t work) what I made wrong? :confused:

The script aparently don’t reach the first print that is the “print(“Found Value”)”

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Skins = ReplicatedStorage.Skins

game.Players.PlayerAdded:Connect(function(player)
	for index, Object in pairs(player:WaitForChild("Inventory"):GetDescendants()) do
		if Object:IsA("NumberValue") and Object.Value == 1 then
			print("Found Value")
			local CharacterClone = Skins:FindFirstChild(Object.Name)
			CharacterClone.Parent = workspace.MainGame.Skins
			
			CharacterClone.Weapon.Middle.CFrame = player.Character:WaitForChild("Right Arm").CFrame
			CharacterClone.RightArm.Middle.CFrame = player.Character:WaitForChild("Right Arm").CFrame
			CharacterClone.LeftArm.Middle.CFrame = player.Character:WaitForChild("Left Arm").CFrame
			CharacterClone.RightLeg.Middle.CFrame = player.Character:WaitForChild("Right Leg").CFrame
			CharacterClone.LeftLeg.Middle.CFrame = player.Character:WaitForChild("Left Leg").CFrame
			CharacterClone.Torso.Middle.CFrame = player.Character:WaitForChild("Torso").CFrame
			CharacterClone.Head.Middle.CFrame = player.Character:WaitForChild("Head").CFrame
			print("Setted CFrame")
			CharacterClone.Weapon.Middle.WeldConstraint.Part1 = player.Character:WaitForChild("Right Arm")
			CharacterClone.Head.Middle.WeldConstraint.Part1 = player.Character:WaitForChild("Head")
			CharacterClone.Torso.Middle.WeldConstraint.Part1 = player.Character:WaitForChild("Torso")
			CharacterClone.RightArm.Middle.WeldConstraint.Part1 = player.Character:WaitForChild("Right Arm")
			CharacterClone.LeftArm.Middle.WeldConstraint.Part1 = player.Character:WaitForChild("Left Arm")
			CharacterClone.RightLeg.Middle.WeldConstraint.Part1 = player.Character:WaitForChild("Right Leg")
			CharacterClone.LeftLeg.Middle.WeldConstraint.Part1 = player.Character:WaitForChild("Left Leg")
			CharacterClone.Animations.Parent = player.Character
			CharacterClone.BodyColors.Parent = player.Character
		        print("Setted Parent")
               end
	end
end)

Replicated Storage:
image
Player Folder:
image

Hey there. Try changing :GetDescendants() to :GetChildren(). If there are no descendants, then the script will not get to the next line. The inventory only has a child. Unless you are parenting something to the “Scout”, using :GetDescendants() will not work, at least to my knowledge.

2 Likes

I’m not sure about that… I haven’t used :GetDescendants() much, but reading a little bit on it, It does appear to work like :GetChildern, returning the immediate children, but then returning the Children of that Immediate children and so on until all Descendants are returned. Though for this case, it probably is better preformance wise to Use :GetChildren() as it seems :GetDescendants() could be very wasteful …


Where is the location of your script (The parent of it) and what type of script is it?

Have you tried other prints to see if it even runs at all like this?

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Skins = ReplicatedStorage.Skins
print("Script is Actively running!")
--rest of code...
1 Like

Try to wait until the folder has 1 child or more before running the for loop. The value might be created after it runs. You can do this before running the loop

repeat wait() until #player:WaitForChild("Inventory"):GetChildren() > 0
1 Like

As I know of GetDescendants() is that it gets everything like for example: if there is 2 folders inside a model he will search inside the model and inside the folders to find what you want (Values, etc) even if in one of those folders there is nothing the GetDescendants() ain’t gonna stop searching, the GetChildren() only get what is inside the model ignoring if there is something inside the folders, I don’t know if its truly correct but at least at my knowledge it is

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