This script gives me one coin for the block. I want to make it where one block is on top of the other and the top one has to be taken before the Bottom one.
script.Parent.Touched:connect(function(part) if game.Players:findFirstChild(part.Parent.Name) then local plr = game.Players:findFirstChild(part.Parent.Name) plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 1 end end) local debounce = true script.Parent.Touched:connect(function(part) if debounce then debounce = false if game.Players:findFirstChild(part.Parent.Name) then local plr = game.Players:findFirstChild(part.Parent.Name) plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value +1 script.Parent:destroy() end end end)
My first question is why do you have 2 touched functions? Combine them together.
And for your question, just put an if statement in,
if script.Parent:FindFirstChild("TopBrick") then print("Get the top block!") else --Text to give money and destroy block end
I tried this and this is the code I tried. Is it wrong? it didn't work.
if script.Parent:FindFirstChild("TopBrick") then Print(hi) else script.Parent.Touched:connect(function(part) if game.Players:findFirstChild(part.Parent.Name) then local plr = game.Players:findFirstChild(part.Parent.Name) plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 1 end end) local debounce = true script.Parent.Touched:connect(function(part) if debounce then debounce = false if game.Players:findFirstChild(part.Parent.Name) then local plr = game.Players:findFirstChild(part.Parent.Name) plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value +1 script.Parent:destroy() end end end)