hey guys i just picked up scripting today and am attempting to create a dummy that dies when they are clicked and then respawn. Honestly i dont know what im doing but so far i havent been stuck on something for this long. Basically the dummy does respawn once killed but clicking on them again does nothing and they dont die. I then get the error in the title, if you guys could help me i would be very grateful. I did look this up before posting and found that this happens if the script tries to find the humanoid before it exists but the humanoid is always there long before the script tries to find it so idk. Here is my script
local pdummy = game.Workspace["respawning dummy 1"]["Player Dummy"] local spdummy = game.ServerStorage["Player Dummy"] local clickdetector = game.Workspace["respawning dummy 1"]["Player Dummy"]["HumanoidRootPart"]["ClickDetector"] clickdetector.MouseClick:Connect (function() pdummy.Torso.WeldConstraint.Enabled = false pdummy.Head.WeldConstraint.Enabled = false pdummy["Left Leg"].WeldConstraint.Enabled = false pdummy["Right Leg"].WeldConstraint.Enabled = false pdummy["Left Arm"].WeldConstraint.Enabled = false pdummy["Right Arm"].WeldConstraint.Enabled = false wait(0.1) local explosion = Instance.new("Explosion",pdummy) explosion.BlastRadius = 5 explosion.ExplosionType = Enum.ExplosionType.NoCraters explosion.Position = pdummy.Torso.Position explosion.BlastPressure = 500000 explosion.DestroyJointRadiusPercent = 0 pdummy.Head.oof.Playing = true pdummy.Humanoid.Health = 0 wait (2) end) while true do wait(5) if pdummy.Humanoid.Health == 0 then pdummy:Destroy() copy=spdummy:clone() spdummy.Parent = game.Workspace["respawning dummy 1"] spdummy = pdummy end
There are few issues with your script. First of all, when you are cloning the dummy, instead of parenting the clone (copy), you are parenting the template. Correct code should look like this:
pdummy:Destroy() copy = spdummy:clone() copy.Parent = game.Workspace["respawning dummy 1"] pdummy = copy --copy is now the new dummy
Now the more serious problem. Your click detector connection is still connected to the old (now destroyed) dummy. You have to make a new connection everytime a new dummy appears. So your whole script should look like this:
local pdummy = game.Workspace["respawning dummy 1"]["Player Dummy"] local spdummy = game.ServerStorage["Player Dummy"] local clickdetector = game.Workspace["respawning dummy 1"]["Player Dummy"]["HumanoidRootPart"]["ClickDetector"] local function OnClick() --name your function, so you can reuse it pdummy.Torso.WeldConstraint.Enabled = false pdummy.Head.WeldConstraint.Enabled = false pdummy["Left Leg"].WeldConstraint.Enabled = false pdummy["Right Leg"].WeldConstraint.Enabled = false pdummy["Left Arm"].WeldConstraint.Enabled = false pdummy["Right Arm"].WeldConstraint.Enabled = false wait(0.1) local explosion = Instance.new("Explosion",pdummy) explosion.BlastRadius = 5 explosion.ExplosionType = Enum.ExplosionType.NoCraters explosion.Position = pdummy.Torso.Position explosion.BlastPressure = 500000 explosion.DestroyJointRadiusPercent = 0 pdummy.Head.oof.Playing = true pdummy.Humanoid.Health = 0 wait (2) end clickdetector.MouseClick:Connect (OnClick) --connect here while true do wait(5) if pdummy.Humanoid.Health == 0 then pdummy:Destroy() copy = spdummy:clone() copy.Parent = game.Workspace["respawning dummy 1"] pdummy = copy --make the new connection clickdetector = pdummy["HumanoidRootPart"]["ClickDetector"] --click detector from the new clone clickdetector.MouseClick:Connect (OnClick) -- connect clone (copy) clickdetector end
Have a nice scripting session!
EDIT: BTW, do not worry about disconnecting the old connection as server will do that automatically during Destroy() function.