So i want to make breakable planks. I want them to break by shooting them few times, and then breaking into pieces like normal shattering glass does, but also emitting different sound.
I have tried searching but found no information about what i need, and also tried to look at codes of FE gun kit but i dont know how to edit it correctly to implement that.
make a numbervalue inside the plank named “Health” with the value being its health.
ShatterGlass.OnServerEvent:Connect(function(Player, Hit:BasePart?, Pos, Dir)
if Hit then
if Hit.Name == "_glass" then --It can be _plank but that would require editing every gun client script.
if Hit.Health.Value > 0 and Hit.Transparency == 1 then -- YAY
Hit.Healh.Value -= 15 -- damage. -- base health is 100. : )
local Sound:Sound? = Instance.new("Sound") -- SFX Hit.
Sound.RollOffMaxDistance = 70
Sound.Volume = 0.7
Sound.SoundId = "rbxassetid://4004052860"
Sound.Parent = Hit
Sound:Play()
game:GetService("Debris"):AddItem(Sound, Sound.TimeLength - 0.1)
else -- gone?
local Sound:Sound? = Instance.new("Sound") -- SFX Hit.
Sound.RollOffMaxDistance = 70
Sound.Volume = 0.7
Sound.SoundId = "rbxassetid://158712406"
Sound.Parent = Hit
Sound:Play()
game:GetService("Debris"):AddItem(Sound, Sound.TimeLength - 0.1)
--- Hit.Transparency = 1 -- nvm the glass shatter does it
task.delay(2,function()
Hit:Destroy()
--Hit.Transparency = 0 -- or if you awnna make it respawn : )
--Hit.Health.Value = 100 -- delete the comments if you wanna do the second option.
end)
GlassShattering:Shatter(Hit, Pos, Dir + Vector3.new(math.random(-25, 25), math.random(-25, 25), math.random(-25, 25)))
end
end
end
end)
Ohhh so i can now detect maximum health of _glass object to set different sounds on break, am i right? Or should i add extra code strings to separate inside of function to make it work properly with different sounds? (i know i will need to get new “Maxhealth” numbervalue to it, no need to tell, and i will use it for extra stuff also, such as repairing structures later in development, thats why i will call it Maxhealth, not material or smth)
Yes the snippet does that for you, if plank health is above 0 then damage it for 15, if not shatter it then destroy it after 2 seconds, you can respawn it too if you wanna.
As for Material you can just use.
ShatterGlass.OnServerEvent:Connect(function(Player, Hit:BasePart?, Pos, Dir)
if Hit then
if Hit.Name == "_glass" then --It can be _plank but that would require editing every gun client script.
if Hit.Material == Enum.Material.WoodPlanks then -- ?
if Hit.Health.Value > 0 and Hit.Transparency == 1 then -- YAY
Hit.Healh.Value -= 15 -- damage. -- base health is 100. : )
local Sound:Sound? = Instance.new("Sound") -- SFX Hit.
Sound.RollOffMaxDistance = 70
Sound.Volume = 0.7
Sound.SoundId = "rbxassetid://4004052860"
Sound.Parent = Hit
Sound:Play()
game:GetService("Debris"):AddItem(Sound, Sound.TimeLength - 0.1)
else -- gone?
local Sound:Sound? = Instance.new("Sound") -- SFX Hit.
Sound.RollOffMaxDistance = 70
Sound.Volume = 0.7
Sound.SoundId = "rbxassetid://158712406"
Sound.Parent = Hit
Sound:Play()
game:GetService("Debris"):AddItem(Sound, Sound.TimeLength - 0.1)
--- Hit.Transparency = 1 -- nvm the glass shatter does it
task.delay(2,function()
Hit:Destroy()
--Hit.Transparency = 0 -- or if you awnna make it respawn : )
--Hit.Health.Value = 100 -- delete the comments if you wanna do the second option.
end)
GlassShattering:Shatter(Hit, Pos, Dir + Vector3.new(math.random(-25, 25), math.random(-25, 25), math.random(-25, 25)))
end
end
end
end
end)
When i shoot them few times which must be enough to shatter, even glass which is set to 15 health, they do not shatter, bullets go thru the _glass objects.
ShatterGlass.OnServerEvent:Connect(function(Player, Hit:BasePart?, Pos, Dir)
if Hit then
if Hit.Name == "_glass" then --It can be _plank but that would require editing every gun client script.
if Hit.Material == Enum.Material.WoodPlanks then -- ?
if Hit.Health.Value > 0 and Hit.Transparency ~= 1 then -- YAY
Hit.Healh.Value -= 15 -- damage. -- base health is 100. : )
local Sound:Sound? = Instance.new("Sound") -- SFX Hit.
Sound.RollOffMaxDistance = 70
Sound.Volume = 0.7
Sound.SoundId = "rbxassetid://4004052860"
Sound.Parent = Hit
Sound:Play()
game:GetService("Debris"):AddItem(Sound, Sound.TimeLength - 0.1)
else -- gone?
local Sound:Sound? = Instance.new("Sound") -- SFX Hit.
Sound.RollOffMaxDistance = 70
Sound.Volume = 0.7
Sound.SoundId = "rbxassetid://158712406"
Sound.Parent = Hit
Sound:Play()
game:GetService("Debris"):AddItem(Sound, Sound.TimeLength - 0.1)
--- Hit.Transparency = 1 -- nvm the glass shatter does it
task.delay(2,function()
Hit:Destroy()
--Hit.Transparency = 0 -- or if you awnna make it respawn : )
--Hit.Health.Value = 100 -- delete the comments if you wanna do the second option.
end)
GlassShattering:Shatter(Hit, Pos, Dir + Vector3.new(math.random(-25, 25), math.random(-25, 25), math.random(-25, 25)))
end
end
end
end
end)
ShatterGlass.OnServerEvent:Connect(function(Player, Hit, Pos, Dir)
ShatterGlass.OnServerEvent:Connect(function(Player, Hit:BasePart?, Pos, Dir)
if Hit then
if Hit.Name == "_glass" then --It can be _plank but that would require editing every gun client script.
if Hit.Material == Enum.Material.WoodPlanks then -- ?
if Hit.Health.Value > 0 and Hit.Transparency ~= 1 then -- YAY
Hit.Health.Value -= 15 -- damage. -- base health is 100. : )
local Sound:Sound? = Instance.new("Sound") -- SFX Hit.
Sound.RollOffMaxDistance = 70
Sound.Volume = 0.7
Sound.SoundId = "rbxassetid://4004052860"
Sound.Parent = Hit
Sound:Play()
game:GetService("Debris"):AddItem(Sound, Sound.TimeLength - 0.1)
elseif Hit.Health.Value <= 0 then -- gone?
local Sound:Sound? = Instance.new("Sound") -- SFX Hit.
Sound.RollOffMaxDistance = 70
Sound.Volume = 0.7
Sound.SoundId = "rbxassetid://158712406"
Sound.Parent = Hit
Sound:Play()
game:GetService("Debris"):AddItem(Sound, Sound.TimeLength - 0.1)
--- Hit.Transparency = 1 -- nvm the glass shatter does it
task.delay(2,function()
Hit:Destroy()
--Hit.Transparency = 0 -- or if you awnna make it respawn : )
--Hit.Health.Value = 100 -- delete the comments if you wanna do the second option.
end)
GlassShattering:Shatter(Hit, Pos, Dir + Vector3.new(math.random(-25, 25), math.random(-25, 25), math.random(-25, 25)))
end
end
end
end
end)
end)