i am currently creating a mining game and im trying to add breakable blocks. so im trying to create a script when broken put ruby into StarterPack. my files:
Ruby(part):
Hit(click)
ParticleEmitter(particle emitter)
ClickDetector(clickdetector):
Script(script)
Ruby(tool)
StarterPack: pickaxe(tool): (not a part of the script)
script:
local debounce = false
-- settings
local cooldown = 0.3
local hp = 5
local particleduration = 0.3
--functions
local function particle() --function for the particle
particlee.Enabled = true
wait(particleduration)
particlee.Enabled = false
end
--main code
function onMouseClick() --detect if player clicked on part
if debounce == false then --check for cooldown
debounce = true --start cooldown
particle() --spawn particles
hitcount.Value += 1 -- damage block
if hitcount.Value == hp then --check if block is damaged enought to break
block:Destroy() --destroy the block
end
wait(cooldown) --cooldown
debounce = false --remove cooldown
end
end
clickDetector.MouseClick:connect(onMouseClick)