How would I edit the classic sword script to solve this issue?

  1. What do you want to achieve? I want the players character to teleport back to one of my teleports upon dying by a kill part or classic sword.

  2. What is the issue? The event will only fire once.

  3. What solutions have you tried so far? I do not know of any solutions just yet.

players[i].Character.Humanoid.HealthChanged:Connect(function()
			if players[i].Character.Humanoid.Health == 0 then
				print("health changed")
				players[i].Character.Humanoid.Health = 100
				print("health updated")
				players[i].Character.HumanoidRootPart.CFrame = CFrame.new(workspace.GameSystem.Teleports["Part"..math.random(8)].Position)
				players[i].Character.Parent = workspace.GameSystem.playersIngame
				print("teleported?")
			end
	
		end)
6 Likes

You will have to disable the humanoids death state for this to work I think.

humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false)

5 Likes

For some reason the character just freezes when they get killed with the sword or reset with that?

4 Likes

You’ll have to manually use :LoadCharacter() on them if their death state is disabled.

So you would do:

→ LoadCharacter
→ Teleport

4 Likes

why would I load the character before I teleport it?

3 Likes

They won’t respawn otherwise since you disabled the death state. I’m not sure what your goal is though, do you only want this random spawn to happen with kill part and sword or anytime they die?

3 Likes

Actually it still doesn’t work. I want it all times they die. Ill send you the code.

3 Likes


Now they just don’t teleport and go to spawn when reset. Also why wont Humanoid.Died event work?

3 Likes


why does this not work either

3 Likes

You need to set their humanoid state type on the client as well I think so in a local script.
You probably dont need to use the loadcharacter then either since their character should stay intact.

Humanoid.Died does not fire because you set their state type to disabled on the server.

4 Likes

why do i need to set the death state to false though with .Died

2 Likes

You need to do this if you dont want the character to die, I assumed this from your original code where you tried setting their health back to 100.

Another way you could handle this if you don’t need that and just want people to always spawn randomly is to do this on Player.CharacterAdded event and just move the character on respawning.

Theres multiple ways you can do this but it depends on what you’re trying to achieve.

3 Likes

oh no, I do want the character to die and then respawn to the teleport.

image
with this code it does not work when they reset or get killed by a sword though

3 Likes

ill try the character added event too though

1 Like

You should just have something like this then

Player.CharacterAdded:Connect(function(character)
-- put their character in the folder you want
-- set the characters position
end)
3 Likes


now they just freeze on the kill part

2 Likes

You have removed the death state being disabled right?

2 Likes

yes, this is what i have. Now the player resets correctly with the kill part, but when they respawn they disappear and freeze

2 Likes

image
simplified to this how do i edit this cus now when the player resets they load to spawn

2 Likes

seems that the humanoid.Died event does not fire when i reset

2 Likes