How do I have my character earn "points" after touching a part? (cloned part)

So i’m working on a “pick up trash” game that’s similar to a simulator. But currently i’m stuck trying to get the pick up system working.

The Problem: You pick it up and earn a point(good), but then after the piece of trash respawns you’re no longer able to get points from it.

game.Players.PlayerAdded:Connect(function(player)
			local debounce = true
			script.Parent.Touched:connect(function()
				local plr = player.leaderstats.Plastic
				if debounce then
					debounce = false
					plr.Value = plr.Value +1
					wait(2)
					debounce = true
				end
			end)
		end)

local wp = script.Parent
local toggle = false

wp.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil and not toggle then
		toggle = true

local wpClone = wp:Clone()
wp:Destroy()
wait(10)
wpClone.Parent = workspace
		toggle = false
		end
end)

This is the regular script i’m working with, and it sets the new clone to a parent(or is supposed to) but it doesn’t give a point after the respawn. Can I get some help?

I think it is because of the playeradded event

game.Players.PlayerAdded:Connect(function(player)
	local stats = Instance.new("Folder")
	stats.Name = "leaderstats"
	stats.Parent = player
	
	local Plastic = Instance.new("IntValue")
	Plastic.Name = "Plastic"
	Plastic.Value = 0
	Plastic.Parent = stats
	
	local Cash = Instance.new("IntValue")
	Cash.Name = "Cash"
	Cash.Value = 0
	Cash.Parent = stats
end)

My leaderboard

After it’s removed the “local plr” doesn’t know what a player is

Its because the touched event is referencing the part and not the cloned part.

Ok, how do i fix that?


30Characters

And one person touching it counts for everyone

It’s getting a value that is set for everyone. You most likely messed up your pointer.

Ok, how do I fix it

Edit: Never mind I just need to figure out how to make it respawn somewhere else

Please mark a solution, thanks!

but I did I myself…

anyway i’m trying to get it to change positions after touched but as usual it’s not working

local wappa = script.Parent
local dp = true
local pst = {Vector3.new(133, 3.5, 40), Vector3.new(-164, 3.5, 47), Vector3.new(-165, 3.5, 203)}
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		if dp == true then 
			dp = false
			script.Parent.Transparency = 1
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			player.leaderstats.Plastic.Value = player.leaderstats.Plastic.Value + 1
			script.Parent.Transparency = 1
			wait(5)
			dp = true
			math.randomseed(tick())
			local posi = pst[math.random(1, #pst)]
			wappa.Position = posi
			script.Parent.Transparency = 0
		end
	end
end)

don’t judge the wappa

Well start putting print statements before and after where you think the problem is going on and also, dont put math.randomseed inside of the touched function but it outside like where youd put variables

1 Like

Found the solution the part wasn’t anchored

1 Like

Please mark your answer as a solution.