I want to detonate a Dummy by pressing a button. This should be possible endless times.
The Dummy only explodes once and then the explosion on other dummies is ignored.
I’ve tried all kinds of ways but I just can’t fix it.
Button script:
local Model = script.Parent
local ClickDetector = Model.Button.ClickDetector
local SurfaceGui = Model.DisplayPart.SurfaceGui
local function MouseClick()
if workspace:FindFirstChild("Dummy") then
local TortureModule = require(game:GetService("ServerStorage").ModuleScripts.TortureModule)
TortureModule.Explode(workspace.Dummy)
end
end
ClickDetector.MouseClick:Connect(MouseClick)
A piece of the module script:
function TortureModule.Explode(Dummy)
Dummy:SetAttribute("CanChat", false)
ChatModule.Chat(Dummy.Head, "I'm explosion proof!")
task.wait(1)
if workspace:FindFirstChild(Dummy) then
local Explosion = Instance.new("Explosion", workspace)
Explosion.Position = Dummy.PrimaryPart.Position
end
end
Thank you in advance if you read this and especially if you can help me!
I’m assuming there are multiple dummies you want to be exploded (prove me if I’m wrong).
In this case, you are only getting ONE dummy from workspace in the button script
1 Like
Sorry for the unclearance, I spawn a dummy every time one dies. The dummy that has died is given a new name “Corpse”. (There is only one dummy at once)
What script are you using to spawn the next dummy? It should be in the ModuleScript after the explosion part then return the dummy back to the ButtonScript where you can define a variable like NewDummy
Try changing the button script to
local Model = script.Parent
local ClickDetector = Model.Button.ClickDetector
local SurfaceGui = Model.DisplayPart.SurfaceGui
local function MouseClick()
if workspace:FindFirstChildWhichIsA("Dummy") then
local TortureModule = require(game:GetService("ServerStorage").ModuleScripts.TortureModule)
TortureModule.Explode(workspace.Dummy)
end
end
ClickDetector.MouseClick:Connect(MouseClick)
1 Like
There is a function in the Module to spawn a new Dummy:
function TortureModule.New()
if not workspace:FindFirstChild("Dummy") then
local ServerStorage = game:GetService("ServerStorage")
local Dummy = ServerStorage.Dummy:Clone()
Dummy.Parent = workspace
end
end
Could you explain how I return the Dummy?
This results in my Module not doing anything.
I take it back, it’s actually a dumb idea
Btw, don’t do this:
Do this instead:
local Explosion = Instance.new("Explosion")
Explosion.Position = Dummy.PrimaryPart.Position
Explosion.Parent = Dummy.PrimaryPart
It’s not good practice to parent a new inserted object immediately. You should always parent the object last.
1 Like
Fixed the issue by changing one line of code:
if workspace:FindFirstChild(Dummy) then
if workspace:FindFirstChild(Dummy.Name) then
Thank you for thinking along.