Basketball collection script not working

My Goal: whenever you touch the happyBasketball it duplicates in your folder

problem: Not doing that

collectionScript

local happyBasketball = basketballList:WaitForChild(“happyBasketball”)

basketball.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
local character = hit.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player then
local collectedFile = player.basketballsCollected
local found = collectedFile:FindFirstChild(“happyBasketball”)
end
end
end)

savingScript

local DataStoreService = game:GetService(“DataStoreService”)
local collectedDataStore = DataStoreService:GetDataStore(“collected”)
local replicatedStorage = game:GetService(“ReplicatedStorage”)
local basketballList = replicatedStorage:WaitForChild(“basketballs”)

game.Players.PlayerAdded:Connect(function(player)
local basketballsCollected = Instance.new(“Folder”, player)
basketballsCollected.Name = “basketballsCollected”

local success, errormessage = pcall(function()
	local basketballs = collectedDataStore:GetAsync("User-"..player.UserId)
	if basketballs then
		for i, v in pairs(basketballs) do
			local basketballFound = basketballList:FindFirstChild(v)
			if basketballFound then
				basketballFound:Clone().Parent = basketballsCollected
			end
		end
	end
end)

end)

game.Players.PlayerRemoving:Connect(function(player)

local success, errormessage = pcall(function()
	local collectedSave = {}
	for i, basketball in pairs(player.basketballsCollected:GetChildren()) do
		if basketball then
			table.insert(collectedSave,basketball.Name)
		end
	end
	collectedDataStore:SetAsync("User-"..player.UserId,collectedSave)
end)

end)

game:BindToClose(function(player)

local success, errormessage = pcall(function()
	local collectedSave = {}
	for i, basketball in pairs(player.basketballsCollected:GetChildren()) do
		if basketball then
			table.insert(collectedSave,basketball.Name)
		end
	end
	collectedDataStore:SetAsync("User-"..player.UserId,collectedSave)
end)

end)

Change the basketball to happyBasketball, I can’t find the basketball variable, I think you meant happyBasketball

my boolvalue is named happybasketball and I had varible for basketball at the top

well can I see the entire script?

local Players = game:GetService(“Players”)
local basketball = script.Parent
local replicatedStorage = game:GetService(“ReplicatedStorage”)
local basketballList = replicatedStorage:WaitForChild(“basketballs”)
local happyBasketball = basketballList:WaitForChild(“happyBasketball”)

basketball.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
local character = hit.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player then
local collectedFile = player.basketballsCollected
local found = collectedFile:FindFirstChild(“happyBasketball”)
end
end
end)

this is collectionScript for my happybasket im making a find the basketball game

@RocketB0ii is there anything wrong with it?

how about your explorer? 30s

The parts are with decals and the happyBasketball has the collectionScript inside of it but I didn’t name them is that a problem?

make it print something between these lines? because print statement is the best debugging tool, change my mind

It did not print anything I said hi but i didn’t work

wait i touched it said hi

so when you touch it does not go into the basketballsCollected folder i created into the player can I clone it and put the clone in the folder?

do you want to see the savingScript I think it has something to do with it

local DataStoreService = game:GetService(“DataStoreService”)
local collectedDataStore = DataStoreService:GetDataStore(“collected”)
local replicatedStorage = game:GetService(“ReplicatedStorage”)
local basketballList = replicatedStorage:WaitForChild(“basketballs”)

game.Players.PlayerAdded:Connect(function(player)
local basketballsCollected = Instance.new(“Folder”, player)
basketballsCollected.Name = “basketballsCollected”

local success, errormessage = pcall(function()
	local basketballs = collectedDataStore:GetAsync("User-"..player.UserId)
	if basketballs then
		for i, v in pairs(basketballs) do
			local basketballFound = basketballList:FindFirstChild(v)
			if basketballFound then
				basketballFound:Clone().Parent = basketballsCollected
			end
		end
	end
end)

end)

game.Players.PlayerRemoving:Connect(function(player)

local success, errormessage = pcall(function()
	local collectedSave = {}
	for i, basketball in pairs(player.basketballsCollected:GetChildren()) do
		if basketball then
			table.insert(collectedSave,basketball.Name)
		end
	end
	collectedDataStore:SetAsync("User-"..player.UserId,collectedSave)
end)

end)

game:BindToClose(function(player)

local success, errormessage = pcall(function()
	local collectedSave = {}
	for i, basketball in pairs(player.basketballsCollected:GetChildren()) do
		if basketball then
			table.insert(collectedSave,basketball.Name)
		end
	end
	collectedDataStore:SetAsync("User-"..player.UserId,collectedSave)
end)

end)

great, now how about these lines

wait a minute I see nothing that “duplicates” to the folder

local Players = game:GetService(“Players”)
local basketball = script.Parent
local replicatedStorage = game:GetService(“ReplicatedStorage”)
local basketballList = replicatedStorage:WaitForChild(“basketballs”)
local happyBasketball = basketballList:WaitForChild(“happyBasketball”)

basketball.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild(“Humanoid”) then
        local character = hit.Parent
        local player = game.Players:GetPlayerFromCharacter(character)
        
        if player then
            local collectedFile = player.basketballsCollected
            local found = collectedFile:FindFirstChild(“happyBasketball”)
            
            if not found then
                basketballList:Clone().Parent = collectedFile -- I guess this is how you will do it
            end
        end
    end
end)

Do I copy this script idk or did you just add spmething

the thing worked the problem is that it duplicated the whole folder and the other basketball values in the basketballsCollected folder is there a way we can change the just to be the happyBasketball boolValue

I need just the boolValue to dupilicate into the basketballsCollected Folder in the player