Hello developers.i made a bomb that clones to workspace after tool is activated,but the bomb is getting destroyed after its parented to workspace.im %100 sure its not falling to void.the cancollide is being true after bomb cloned.but even destroys itself.
so i tried anchoring it and the bomb has not destroyed.after its unanchored the bomb got destroyed.
in my previous game i didnt had this issue.what could be wrong with this again?
script(with anchor method)
local Handle = script.Parent.Handle
local TS = game:GetService("TweenService")
local DB = false
script.Parent.Activated:Connect(function()
if DB then
return
end
DB = true
local bomb = Handle:Clone()
bomb.Name = "Bomb"
bomb.Anchored = true
bomb.Parent = workspace
bomb.CanCollide = true
bomb.Planted:Play()
Handle:Destroy()
task.wait(5)
bomb.Anchored = false
local timer = 10
repeat
timer -= 1
bomb.Beep:Play()
TS:Create(bomb,TweenInfo.new(0.5,Enum.EasingStyle.Linear),{Color = Color3.fromRGB(255,0,0)}):Play()
TS:Create(bomb,TweenInfo.new(0.5,Enum.EasingStyle.Linear),{Color = Color3.fromRGB(0,0,0)}):Play()
until timer == 0 or timer < 1
bomb.Explosion:Play()
local Explosion = Instance.new("Explosion",bomb)
Explosion.Position = bomb.Position
Explosion.DestroyJointRadiusPercent = 0
bomb:Destroy()
task.wait(1)
Explosion:Destroy()
end)
For your answer about the cloned part deleting when parented to workspace, it appears to do so after the Explosion instance is created.
From the looks of your code its function appears to act as a single-use bomb that detonates in 10 seconds when activated.
I recommend making the bomb’s layout to look something like this: The Script should act as spawning the bomb. The BombScript should act as the bomb exploding.
My adjustments with the activated code:
local Handle = script.Parent.Handle
local TS = game:GetService("TweenService")
local DB = false
script.Parent.Activated:Connect(function()
if DB then
return
end
DB = true
local bomb = Handle:Clone()
local BombCode = script.BombScript:Clone() --Gets the script so the bomb can function.
bomb.Name = "Bomb"
bomb.Parent = workspace
bomb.CanCollide = true
bomb.Planted:Play()
script.Parent:Destroy() --Should be using this instead of Handle:Destroy() if single-use
BombCode.Parent = bomb
BombCode.Disabled = false --makes the code work!
--You can code this to your liking :)
end)
BombScript’s code:
local TS = game:GetService("TweenService") --the service used for tweenservice
local Debris = game:GetService("Debris") --A service used for scheduling a timed deletion of something.
local bomb = script.Parent --the script.Parent should be the cloned Handle that is named "Bomb"
task.wait(5)
local timer = 10
repeat
wait(1)
timer -= 1
bomb.Beep:Play()
until timer == 0 or timer < 1
--Makes the bomb turn red!
TS:Create(bomb,TweenInfo.new(0.5,Enum.EasingStyle.Linear),{Color = Color3.fromRGB(255,0,0)}):Play()
task.wait(0.5) --perhaps a wait for half a second since the tweenservice waits for 0.5 seconds.
--To make sure the explosion sound plays!
bomb.Explosion:Play()
bomb.Transparency = 1
bomb.Anchored = true
--Schedules a deletion time.
Debris:AddItem(bomb, 2) --The 2 can be changed to how long does the explosion sound effect lasts!
--The explosion!
local Explosion = Instance.new("Explosion")
Explosion.Parent = workspace
Explosion.Position = bomb.Position
Explosion.DestroyJointRadiusPercent = 0
--Again, you can change the code to your liking :)
When bomb is planted it should appear like this in the workspace!
I know that I provided extra help but I just felt like helping people
Sorry for not replying a while i had to sleep but i tried your help and the issue is actually fixed!. thank you so much for helping me.i think ill do same thing when making something clone to workspace