Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I am making a one dollar bill and attempting to clone it. Why doesn't the clone function?

I am making 3d 1 Dollar bill in Roblox Studio, and there is a problem with cloning it. I made a touched event connected to the dollar and tried attempting to make it so once you step on the bill you gain 1 "Money" for the leader stats. It works all well until the clone, once you step on it you destroy the bill but then after 2 seconds the bill respawns so you can get more money but.. The bill only respawns and it does not function again as the script tells it to. Why is this happening?

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

local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local MoneyCollected = Instance.new("IntValue")
MoneyCollected.Name = "Money"
MoneyCollected.Parent = leaderstats
local OneDollar = game.Workspace.OneDollar		
local Onedollar = OneDollar:FindFirstChild("Hitbox")
local OneDollarC = OneDollar:Clone()
local OnedollarC = Onedollar:Clone()
Onedollar.Touched:Connect(function(hit)	

player.leaderstats.Money.Value = player.leaderstats.Money.Value + 1

Onedollar:Destroy()
OneDollar:Destroy()
wait(2)
OneDollarC.Parent = game.Workspace   -- puts it in the workspace but the script doesn't work anymore, why?


end)

end)

-SqmetImesDev

1 answer

You need to connect the .Touched event to the OneDollar that is cloned.

Try this:

local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local MoneyCollected = Instance.new("IntValue")
MoneyCollected.Name = "Money"
MoneyCollected.Parent = leaderstats
local OneDollar = game.Workspace.OneDollar      
local Onedollar = OneDollar:FindFirstChild("Hitbox")
local OneDollarC = OneDollar:Clone()

local event
local hitFunc = function(hit)
	player.leaderstats.Money.Value = player.leaderstats.Money.Value + 1
	
	hit.Parent:Destroy()
	wait(2)
	local newDollar = OneDollarC:Clone()
	local newHitbox = newDollar:FindFirstChild("Hitbox") or newDollar:WaitForChild("Hitbox")
	newDollar.Parent = game.Workspace

	event:disconnect()
	event = newHitbox.Touched:Connect(hitFunc)
end

1 comment

0

Nothing works now, and there is a underline on hitfunc on line 23. Also, its not giving me the error.

This discussion is preserved as it was. New answers, comments, and votes are closed.