I was working on a “Find the smileys game”
and then an error popped up.
for more context, i will give you the scripts I have.
There are 2 scripts, the collection script, (a script that makes it so that you can collect the smiley faces)
and the saving script, which as you can guess, saves your progress.
This is the saving script.
-- Variables
local DataStoreService = game:GetService("DataStoreService")
local collectedDataStore = DataStoreService:GetDataStore("collected")
local replicatedStorage = game:GetService("ReplicatedStorage")
local smileyfaceList = replicatedStorage:WaitForChild("smileyFaces")
game.Players.PlayerAdded:Connect(function(player)
local smileyFacesCollected = Instance.new("Folder",player)
smileyFacesCollected.Name = "smileyFacesCollected"
-- Loading collected smiley faces
local success, errormessage = pcall(function()
local smileyFaces = collectedDataStore:GetAsync("User-"..player.UserId)
if smileyFaces then
for i, v in pairs(smileyFaces) do
local smileyFaceFound = smileyfaceList:FindFirstChild(v)
if smileyFaceFound then
smileyFaceFound:Clone().Parent = smileyFacesCollected
end
end
end
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
-- Saving collected smiley faces
local success, errormessage = pcall(function()
local collectedSave = {}
for i, smileyFace in pairs(player.smileyFacesCollected:GetChildren()) do
if smileyFace then
table.insert(collectedSave,smileyFace.Name)
end
end
collectedDataStore:SetAsync("User-"..player.UserId,collectedSave)
end)
if success then
print("Data has been saved!")
else
print("Data hasn't been saved!")
warn(errormessage)
end
end)
game:BindToClose(function(player)
-- Saving collected smiley faces
local success, errormessage = pcall(function()
local collectedSave = {}
for i, smileyFace in pairs(player.smileyFacesCollected:GetChildren()) do
if smileyFace then
table.insert(collectedSave,smileyFace.Name)
end
end
collectedDataStore:SetAsync("User-"..player.UserId,collectedSave)
end)
end)
And this is the collection script, the one where the error appeared.
local smileyFace = script.Parent
local replicatedStorage = game:GetService("ReplicatedStorage")
local smileyfaceList = replicatedStorage:WaitForChild("smileyFaces")
local smileyFace = smileyfaceList:WaitForChild("smileyFace")
smileyFace.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.smileyFacesCollected
local found = collectedFile:FindFirstChild("smileyFace")
end
end
end)
And this is what I have in my game.
I’ve tried re-naming diffirent parts, but nothing seems to work, I would appreciate any advice.
Thank you.