Find the smileys game error, how can I fix this?

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.
image
image
image

I’ve tried re-naming diffirent parts, but nothing seems to work, I would appreciate any advice.

Thank you.

It looks like you’re attempting to add a Touched event on a bool value, which isn’t possible because a player wouldn’t be able to actually “touch” a bool value. Touched events really only work on BaseParts. What are you trying to achieve here?

Im trying to make it so when a player touches a smiley face, it gets transfered over to the “smileyFacesCollected” folder located in the player.

Just rename the top one because two of them have the same name.

Rename the the top one to whatever?

Yeah and then adjust your code to something like this:

local smileyFacePart = script.Parent
local replicatedStorage = game:GetService("ReplicatedStorage")
local smileyfaceList = replicatedStorage:WaitForChild("smileyFaces")
local smileyFace = smileyfaceList:WaitForChild("smileyFace")

smileyFacePart.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)

Edit: Or you could have removed last local variable:

local smileyFace = script.Parent
local replicatedStorage = game:GetService("ReplicatedStorage")
local smileyfaceList = replicatedStorage:WaitForChild("smileyFaces")
--local smileyFace = smileyfaceList:WaitForChild("smileyFace") <-- this was never used below

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)

I tried it, the error disappeared but nothing happened.

Of course nothing happened because if you look at your code:

It doesn’t really do anything except store data in a variable named collectedFile and found

Sorry if i’m acting dumb, I followed a tutorial and an error popped up, thus I didn’t know what to do.

No no it’s all fine! :sweat_smile: continue with your developing!

Wait, I don’t know what to do.

What are you trying to have happen? Are you trying to set the boolValue to true?

All im really wanting to happen is when I touch a smiley face, the folder from replicated storage, “smiley faces” gets transferred to a folder called smileyFacesCollected.

(The smiley face from the values will be picked by a player, if that player steps on a smiley face.

Ah, alright. I assume you only want the value of the smilyFace they touched to be added, right? Assuming the smily faces are named the same as the values in ReplicatedStorage, you can probably do this.

You can use cloning to your advantage here and then change the parent of the value. Try the following after your if player then:

local smileyTouched = game.ReplicatedStorage.smilyFaces:FindFirstChild(smileyFace.Name):Clone()
smileyTouched.Parent = player.smilyFacesCollected

Thank you, although some names of object were not spelt correctly, it was easily fixable.
Thanks for the information.