Need help with destroying a block on touch

I am trying to destroy a block each time a hammer touches it here is my script:
local hammer = game.StarterPack.Hammer
local Part1 = game.Workspace.Part1

function onHit(hit)
if hit.Parent == hammer then
Part1:Destroy()
end
end

1 Like

What happens when you try that? Like do you get a error?

function onhit(hit)
	if hit.Parent:FindFirstChild("Hammer") then
		game.Workspace.Part1:Destroy()
		print("Success")
	end
end

game.Workspace.Part1.Touched:Connect(onhit)
3 Likes

You could also just make it so if the player clicks there mouse on the object it breaks it.

Oh, I think you reference it as the tool instead of handle.
Use local hammer = game.StarterPack.Hammer.Handle or what part you want it to touch.

Thanks a bunch man, works great now.

Now I need it so that it will give the user cash when destroyed.
Here is my leaderboard script:
game.Players.PlayerAdded:Connect(function(plr)

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

local money = Instance.new("IntValue")
money.Name = "Money" --Put ur currency name here, mine is Money
money.Value = dataStore:GetAsync(plr.UserId) or starterMoney
money.Parent = leaderstats

end)

function onhit(hit)
	if hit.Parent:FindFirstChild("Hammer") then
		game.Workspace.Part1:Destroy()
		print("Success")
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		player.leaderstats.Cash.Value = player.leaderstats.Money.Value + 1
		print("gave points")
	end
end

game.Workspace.Part1.Touched:Connect(onhit)
2 Likes

Thank you so much man, really appreciate your help!

3 Likes