How Can i Fix My Script

so i have this script that when the Values Are 1 it automatically Puts the Character in The Player Folder
this is the Script

local chars = game.ReplicatedStorage:WaitForChild("Characters")

local classNames = {"Accessory", "Shirt", "Pants", "ShirtGraphic", "BodyColors"}


game.Players.PlayerAdded:Connect(function(plr)

	local OwnedCharactersValue = Instance.new("Folder", plr)
	OwnedCharactersValue.Name = "OwnedCharactersValue"

	local leaderstats = Instance.new("Folder", plr)
	leaderstats.Name = "leaderstats"

	local Cash = Instance.new("IntValue", leaderstats)
	Cash.Name = "Cash"
	Cash.Value = 0

	local OwnedCharacters = Instance.new("Folder", plr)
	OwnedCharacters.Name = "OwnedCharacters"
	
	for i, char in pairs(chars:GetChildren()) do

		local NewValue = script.Value:Clone()

		NewValue.Name = char.Name

		NewValue.Parent = OwnedCharactersValue
	end
	
	for i, Giver in pairs(chars:GetChildren()) do
		local CharactersValue = OwnedCharactersValue:GetChildren()
		for i = 1, #CharactersValue do			
			if CharactersValue[i].Value == 1 then
				
				chars.CharactersValue.Name:Clone().Parent = OwnedCharacters
				
			end
		end
	end
	
end)


game.ReplicatedStorage.CharacterRE.OnServerEvent:Connect(function(plr, isBuying, character)

	if not chars:FindFirstChild(character) then
		return
	end

	if isBuying and not plr.OwnedCharacters:FindFirstChild(character) then

		local price = chars:FindFirstChild(character).Price.Value
		local plrCash = plr.leaderstats.Cash
		local OwnedCharactersValue = plr.OwnedCharactersValue

		if price <= plrCash.Value then

			plrCash.Value -= price

			local CharactersValue = OwnedCharactersValue:FindFirstChild(character)

			CharactersValue.Value = 1

			chars[character]:Clone().Parent = plr.OwnedCharacters
		end





	elseif not isBuying and plr.OwnedCharacters:FindFirstChild(character) and plr.Character and plr.Character:FindFirstChild("Humanoid") then

		for i, descendant in pairs(plr.Character:GetDescendants()) do

			if table.find(classNames, descendant.ClassName) or descendant:IsA("Decal") and descendant.Parent.Name == "Head" then

				descendant:Destroy()
			end
		end


		for i, descendant in pairs(plr.OwnedCharacters[character]:GetDescendants()) do

			if table.find(classNames, descendant.ClassName) then

				descendant:Clone().Parent = plr.Character

			elseif descendant:IsA("Decal") and descendant.Parent.Name == "Head" then
				descendant:Clone().Parent = plr.Character.Head
			end
		end
	end
end)

the Script is not really Mine Tbh

1 Like

There’s no value being set here, that’s why the for loop below will not run anything because there isn’t any child that has the value of 1

image
theres a Value That Clones It And It in the OwnedCharactersValue

Yes but the value of the value isn’t 1. I don’t know what the value is either.

what i meant is when the player Has one of the Values is 1 it Automatically gives the Player The Character

Yes, I understand. However your for loop right here:

is checking to see if that NewValue that you parented has the value of 1. I don’t know what the values are but based on what you’ve been saying, the value is not 1. You will need to set the value to 1 for whatever you wanted it to be for.

1 Like