i just made a quick respawn script for a dummy and it works fine but gives this error
Workspace.Dummy.RespawnScript:2: attempt to index nil with 'Humanoid’
Heres the script
while wait() do
if script.Parent.Humanoid.Health == 0 then
local dummy = game.ReplicatedStorage.Dummy
local cd = dummy:Clone()
cd.HumanoidRootPart.CFrame = script.Parent.HumanoidRootPart.CFrame
cd.Parent = game.Workspace
script.Parent:Destroy()
end
end
Assuming that script.Parent is Character of the dummy, try doing:
local char = script.Parent or script.Parent.Parent.CharacterAdded:Wait()
The character instance has to load in workspace when player/dummy is instanced, and the script may run before it, so we’re polling to wait for the character and continue code.
Not sure if i used the code correctly but it errors now with Humanoid is not a valid member of Model "Dummy"
here’s the code now
local Dummy = script.Parent or script.Parent.Parent.CharacterAdded:Wait()
while wait() do
if Dummy.Humanoid.Health == 0 then
local dummy = game.ReplicatedStorage.Dummy
local cd = dummy:Clone()
cd.HumanoidRootPart.CFrame = script.Parent.HumanoidRootPart.CFrame
cd.Parent = game.Workspace
script.Parent:Destroy()
end
end
if Dummy:WaitForChild("Humanoid").Health == 0 then
If that doesn’t work maybe try this:
local Dummy = script.Parent or script.Parent.Parent.CharacterAdded:Wait()
local Humanoid = Dummy:WaitForChild("Humanoid")
while wait() do
if Humanoid.Health == 0 then
local dummy = game.ReplicatedStorage.Dummy
local cd = dummy:Clone()
cd.HumanoidRootPart.CFrame = script.Parent.HumanoidRootPart.CFrame
cd.Parent = game.Workspace
script.Parent:Destroy()
end
end
No longer got the not a valid member error but now have a infinite yield error Infinite yield possible on 'Dummy:WaitForChild(“Humanoid”)'
heres the code
local Dummy = script.Parent or script.Parent.Parent.CharacterAdded:Wait()
while wait() do
if Dummy:WaitForChild("Humanoid").Health == 0 then
local dummy = game.ReplicatedStorage.Dummy
local cd = dummy:Clone()
cd.HumanoidRootPart.CFrame = script.Parent.HumanoidRootPart.CFrame
cd.Parent = game.Workspace
script.Parent:Destroy()
end
end
tried the second bit of code and it errors with Workspace.Dummy.RespawnScript:9: attempt to index nil with 'HumanoidRootPart’
Try renaming Dummy, the script believes you are referencing the actual Dummy itself.
local chr = script.Parent or script.Parent.Parent.CharacterAdded:Wait()
while wait() do
if chr.Humanoid.Health == 0 then
local dummy = game.ReplicatedStorage.Dummy
local cd = dummy:Clone()
cd.HumanoidRootPart.CFrame = script.Parent.HumanoidRootPart.CFrame
cd.Parent = game.Workspace
script.Parent:Destroy()
end
end
Usually when you get the “index nil with” error that means that the object that it’s saying you’re indexing nil with doesn’t exist. In this case the Dummy. I’m assuming it’s meaning the Dummy clone.
switched it to just D and it still gets inf yielded
local D = script.Parent or script.Parent.Parent.CharacterAdded:Wait()
while wait() do
if D:WaitForChild("Humanoid").Health == 0 then
local dummy = game.ReplicatedStorage.Dummy
local cd = dummy:Clone()
cd.HumanoidRootPart.CFrame = script.Parent.HumanoidRootPart.CFrame
cd.Parent = game.Workspace
script.Parent:Destroy()
end
end
try this one, it got inf yileded because script.Parent.Parent.CharacterAdded:Wait() is I believe workspace
local char = script.Parent
local hum = char:WaitForChild("Humanoid")
hum.HealthChanged:Connect(function()
if hum.Health == 0 then
task.wait(1) -- you can delete this
local dummy = game:GetService("ReplicatedStorage"):WaitForChild("Dummy"):Clone()
dummy.Parent = game.Workspace
dummy:WaitForChild("HumanoidRootPart").CFrame = char:WaitForChild("HumanoidRootPart").CFrame
script.Parent:Destroy()
end
end)
local rs = game:GetService("ReplicatedStorage")
local dummy = workspace.Dummy
local humanoid = dummy.Humanoid
while wait() do
if humanoid.Health <= 0 then
dummy:Destroy()
local dummy = game.ReplicatedStorage.Dummy
local cd = dummy:Clone()
cd.HumanoidRootPart.CFrame = dummy.HumanoidRootPart.CFrame
cd.Parent = game.Workspace
end
end