Get script to run on respawn

local PhysicsService = game:GetService("PhysicsService")
PhysicsService:CreateCollisionGroup("UserCollision")
PhysicsService:CollisionGroupSetCollidable("UserCollision", "UserCollision", false)

game:GetService("Players").PlayerAdded:Connect(function(Plr)
	--if Plr.Name == "ElonMask0" then Plr:Kick("Stop joining ") return end
	Plr.CharacterAdded:Connect(function(Chr)
		--Chr.Parent = game:GetService("Workspace"):WaitForChild("Live")
		local Stand = "Whitesnake" --modified later on
		local StandModel = game:GetService("ServerStorage"):WaitForChild("StandModels"):WaitForChild(Stand):Clone()
		StandModel.Parent = Chr
		StandModel.Name = "Stand"
		local Motor6D = Instance.new("Motor6D")
		Motor6D.Name = "StandMotor6D"
		Motor6D.Parent = Chr:WaitForChild("HumanoidRootPart")
		Motor6D.Part0 = Chr.HumanoidRootPart
		Motor6D.Part1 = StandModel:WaitForChild("StandHumanoidRootPart")
		local BlacklistedParts = Instance.new("Folder")
		BlacklistedParts.Name = "BlacklistedParts"
		BlacklistedParts.Parent = StandModel
		for _,v in pairs(StandModel:GetDescendants()) do
			if v:IsA("BasePart") or v:IsA("Decal") or v:IsA("Texture") then
				if v:IsA("BasePart") then
					v.Massless = true
					v.CanCollide = false
				end
				if v.Transparency >0 and v.Transparency <1 then
					local CustomTransparency = Instance.new("NumberValue")
					CustomTransparency.Name = "CustomTransparency"
					CustomTransparency.Value = v.Transparency
					CustomTransparency.Parent = v
				elseif v.Transparency == 1 then
					local Blacklisted = Instance.new("Folder")
					Blacklisted.Name = v.Name
					Blacklisted.Parent = BlacklistedParts
				end
				v.Transparency = 1
			end
		end
		local StandScript = game.ServerStorage:WaitForChild("StandScripts"):WaitForChild(Stand):Clone()
		StandScript.Parent = Plr:WaitForChild("PlayerGui")
		StandScript.Disabled = false
		pcall(function()
			Chr:WaitForChild("Animate"):Destroy()
			local Animate = StandModel:WaitForChild("Animate"):Clone()
			Animate.Parent = Chr
			Animate.Disabled = false
			StandModel.Animate:Destroy()
		end)
		local Hurtbox = Instance.new("Part")
		Hurtbox.Parent = Chr
		Hurtbox.Color = Color3.fromRGB(255,0,0)
		Hurtbox.Material = Enum.Material.Neon
		Hurtbox.Transparency = 1
		Hurtbox.Size = Vector3.new(4.87, 5.27, 4.56)
		Hurtbox.CanCollide = false
		Hurtbox.Massless = true
		Hurtbox.Name = "Hurtbox"
		local Weld = Instance.new("Weld")
		Weld.Parent = Chr.HumanoidRootPart
		Weld.Part0 = Chr.HumanoidRootPart
		Weld.Part1 = Hurtbox
	end)
end)

My script only plays when the player joins the game, however, i need it to play when a character ALSO respawns, how can i do this?

Hi!
I think you can use the CharacterAdded event for that.

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
     Player.CharacterAdded:Connect(function(char)
--// Code that runs on player respawn
     end)
end)

Not sure if this is what you mean, but you can try that.

This isn’t really different from what i currently have i believe

Strange. Worked for me. This is how other developers suggested too:

local Once = false

if Once == false then
Once = true
--- your script
end

This isn’t what i need, I need it to play on respawn, which it doesen’t do

1 Like

Yeah, i thought it’d work too. no idea why it doesen’t

Maybe try the Humanoid.Died event?

game:GetService('Players').PlayerAdded:Connect(function(player)
  player.CharacterAdded:Connect(function(character)
    character:WaitForChild("Humanoid").Died:Connect(function()
      -- things you want to happen
    end)
  end)
end)

Tried a few different things with it, didnt work unfortunately