Need help with a Kill Part

true, it’s pretty inefficient, i didn’t make it too good lol

Can We all Stop Our Suggestions on This Topic? We all are Fighting for No Reason.
The Issue Has Already Been Solved.

1 Like

@Amine360YT you choose which ever one you want do choose but just know there were more people here saying you should have referenced the part by making the part the scripts parent

1 Like

Hello everyone.

I tried a new script:

local killPartFolder = game.Workspace.KillParts
local killParts = killPartFolder:GetChildren()

for i, v in pairs(killParts) do
	v.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			hit.Parent.Humanoid.Health = 0
			print("The player has died")
		end
	end)
end

Is it a good idea?

Ok so I need to explain this a bit in depth

This is OK but it creates lots of connections.
And it will kill other players locally which is weird soooo

Does the script work? Also, using a for i , v in pairs loop is much more efficient than putting kill scripts in multiple parts.

@Feedekaiser , so when a player die, all players die too?

That’s not a huge problem because I think you can just end the connection or create a debounce system so the event doesn’t fire as much.

1 Like

@NinjaPrecarious1 , I updated the script:

local killPartFolder = game.Workspace.KillParts
local killParts = killPartFolder:GetChildren()
local db = false

for i, v in pairs(killParts) do
	v.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			if db == false then
				db = true
				hit.Parent.Humanoid.Health = 0
				print("The player has died")
				wait(3)
				db = false
			end
		end
	end)
end

Is this fine?

No its more like
due to replication and basically the limits of internet, player’s position will not be always accurate on other clients.
Kinda like this

Player1:

ROBLOX: 0,0,0
Player1: 0,1,0

ROBLOX:

ROBLOX: 0,0,.00001
Player1: 0,.9,0

as you can see, the position are different and therefore, when the physics are calculated (which is when Touched fires) it will kill player that its not supposed to kill since you didn’t check if the player’s that being killed is the local player (which is the only thing that’s correct)

Is it good idea the make the local script fire a server event that kills the player?

Check your devforum private messages

The only thing with the solution is that it could easily be exploitable.

1 Like

No as killing the local character replicates it creates delays and lags.

There are always tradeoffs. Replication doesn’t work in a 60hz manner, and if you were to use server scripts it might not always be accurate.

You could just make a loop and then destroy the connection. A debounce system is also something you could do.

Ok, so do you want to know why I think your wrong?

Could a loop work like this?

while wait() do
	script.Parent.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			hit.Parent.Humanoid.Health = 0
		end
	end)
end

EDIT
Still not working

This creates a new connection every .033 seconds
this is EXTREMELY inefficient.

1 Like