How to make model dissapear when player killed

I need help please. I have a script that makes the player die by the model that works but the issue is, is that the model goes into ReplicatedStorage like it’s meant to, but then spawns back in and is in the same area when you died. I want it so the model respawns at the start so it can come after you again.

Script: local teddy = script.Parent
local humanoid = teddy.Humanoid
local function getHumPos()
return (teddy.HumanoidRootPart.Position)
end

local function attack(target, teddyPart)
local distance = (teddyPart.Position - getHumPos()).Magnitude
if distance < 4 and game.Players:GetPlayerFromCharacter(target) then
target.Humanoid.Health = 0
script.Parent.Kill.Disabled = true
game.Workspace.Monster2.Parent = game.ReplicatedStorage
local plr = game.Players:GetPlayerFromCharacter(target)
– jumpscare
if plr.GettingChasedBy.Value == script.Parent then
plr.GettingChased.Value = false
plr.GettingChasedBy.Value = nil
end
end
end

script.Parent.Reached.Event:Connect(function(target)
if target.Character then
if target.Character.Humanoid.Health > 0 then
target.Character.Humanoid.Health = 0
script.Parent.Kill.Disabled = true
wait(1)
game.Workspace.Monster2.Parent = game.ReplicatedStorage
local plr = target
– jumpscare
if plr.GettingChasedBy.Value == script.Parent then
plr.GettingChased.Value = false
plr.GettingChasedBy.Value = nil
end
end
end
end)
local function detection(part, teddyPart)
if part.Parent:FindFirstChild(“Humanoid”) then
local character = part.Parent
if game.Players:GetPlayerFromCharacter(character) then
–Check the player is still alive (And it’s not our own character)
if character.Humanoid.Health > 0 and character ~= teddy then
attack(character, teddyPart)
end
end
end
end

for i,v in pairs(script.Parent:GetDescendants()) do
if v:IsA(“BasePart”) or v:IsA(“MeshPart”) or v:IsA(“UnionOperation”) then
if not string.find(v.Name, “cloth”) then
v.Touched:Connect(function(hit)
detection(hit, v)
end)
end
end
end

I am just posting this to make the code be read more easily:

local teddy = script.Parent
local humanoid = teddy.Humanoid
local function getHumPos()
	return (teddy.HumanoidRootPart.Position)
end

local function attack(target, teddyPart)
	local distance = (teddyPart.Position - getHumPos()).Magnitude
	if distance < 4 and game.Players:GetPlayerFromCharacter(target) then
		target.Humanoid.Health = 0
		script.Parent.Kill.Disabled = true
		game.Workspace.Monster2.Parent = game.ReplicatedStorage
		local plr = game.Players:GetPlayerFromCharacter(target)
		– jumpscare
		if plr.GettingChasedBy.Value == script.Parent then
			plr.GettingChased.Value = false
			plr.GettingChasedBy.Value = nil
		end
	end
end

script.Parent.Reached.Event:Connect(function(target)
	if target.Character then
		if target.Character.Humanoid.Health > 0 then
			target.Character.Humanoid.Health = 0
			script.Parent.Kill.Disabled = true
			wait(1)
			game.Workspace.Monster2.Parent = game.ReplicatedStorage
			local plr = target
			– jumpscare
			if plr.GettingChasedBy.Value == script.Parent then
				plr.GettingChased.Value = false
				plr.GettingChasedBy.Value = nil
			end
		end
	end
end)

local function detection(part, teddyPart)
	if part.Parent:FindFirstChild(“Humanoid”) then
		local character = part.Parent
		if game.Players:GetPlayerFromCharacter(character) then
			–Check the player is still alive (And it’s not our own character)
			if character.Humanoid.Health > 0 and character ~= teddy then
				attack(character, teddyPart)
			end
		end
	end
end

for i,v in pairs(script.Parent:GetDescendants()) do
	if v:IsA(“BasePart”) or v:IsA(“MeshPart”) or v:IsA(“UnionOperation”) then
		if not string.find(v.Name, “cloth”) then
			v.Touched:Connect(function(hit)
				detection(hit, v)
			end)
		end
	end
end
2 Likes

I can help you!

Create a part in workspace and call it SpawnPart or whatever you want, then make it 2 studs higher

The code:

local SpawnPart = game.Workspace.SpawnPart -- Name of the part that the monster will be teleported
game.ReplicatedStorage.Monster2.Head.CFrame = CFrame.new(SpawnPart.Position) -- Teleport the monster

Paste the code under this line:

game.Workspace.Monster2.Parent = game.ReplicatedStorage
1 Like

I just tested this today, and it does not work?

Did you get any errors in the output?