Kill script handler not updating when new values are added

Hi, I’m currently working on a game similar to Tower of Hell though when the round ends the kill script handler no longer works in which I believe is due to the round ending as it makes a new tower folder with new stages so the kill script handler is not checking for the new kill parts.

Script Located in StarterCharacterScripts:

for i, v in pairs (game.Workspace:GetDescendants()) do

	if v:IsA("BoolValue") and v.Name == "Touched" then

		v.Parent.Touched:Connect(function(Hit)

			if Hit.Parent:FindFirstChild("Humanoid") then

				Hit.Parent.Humanoid.MaxHealth = 0
				Hit.Parent.Humanoid.Health = 0
			end
		end)
	end
end

For example it should be possible to make it similar to this though I’m not sure on how to:

function Conveyor(O)
	
	if O.Name ~= "Conveyor" then return end
	if not O:IsA("Part") then return end
	if not O.Parent or not O:WaitForChild("Texture") or not O:WaitForChild("Speed") then return end
	
	O.Velocity = O.CFrame.lookVector * O.Speed.Value
end

game.Workspace.DescendantAdded:Connect(Conveyor)

for _, v in pairs(game.Workspace:GetDescendants()) do
	
	Conveyor(v)
end

Any help is greatly appreciated.

When killing the player make sure its on a server script

Alright so I should change the local script to a script and put it in ServerScriptServices?

Server scripts don’t necessarily need to be in ServerScriptService. You can just copy the code put it in a server script and keep it in StarterCharacterScripts.

I am not 100% sure on this so sorry if I am wrong. I think the problem may be that you are using the script in StarterCharacterScripts which only runs when a character is added(or respawns). When this script runs it connects the touched(kill) event to each of the kill parts in the tower. However, when the round ends it appears the tower is destroyed and a new tower appears(this tower’s kill parts won’t be connected to the touched event because they are different parts). Additionally, because you are only moving the character to the spawn location and not destroying them, they won’t respawn and thus the kill script won’t run again.

I think a possible fix would be to place this script into ServerScriptService and use a bindable event to run it whenever a new tower is made. Also, like @ScriptedPoptartz suggested, make sure it is in a Server Script

I’m sorry if this was too wordy but I hope it helps!

1 Like

Hi, sorry for the late response and I may have given you false information with this topic now being updated, I have also tested it in ServerScriptService with no luck but thanks for trying to help.

Test Reply - Please Ignore This Reply.