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)