Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is my code not damaging other players?

This script is meant to damage everyone except the local player, but instead it does not damage anything. I already tried everything I could think of, anyone have an idea on what to do?

touched = false
local function ontouch(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local hum = hit.Parent:FindFirstChild("Humanoid")
local players = game.Players:GetPlayers()
for i = 1, #players do
	wait()
	local player = players[i]
	repeat wait() until player.Character~= nil
	if player.Character == hum.Parent then	
	if not touched then
		touched = true
			if hit.Parent:FindFirstChild("Humanoid") ~= player.Character.Humanoid then
		print(hit.Parent:FindFirstChild("Humanoid").Parent)
		print("Bye")
		    hum:TakeDamage(5)
	end
	if hit.Parent:FindFirstChild("Humanoid") == player.Character.Humanoid then
		print("Hello")
		print(hit.Parent:FindFirstChild("Humanoid").Parent)
	end
	end
end
end
end
end
script.Parent.Touched:Connect(ontouch)

1 answer

I managed to fix it myself, lol.

touched = false
local function ontouch(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local hum = hit.Parent:FindFirstChild("Humanoid")
local players = game.Players:GetPlayers()
for i = 1, #players do
	wait()
	local player = players[i]
	repeat wait() until player.Character~= nil
	if player.Character ~= hum.Parent then	
	if not touched then
		touched = true
			if hit.Parent:FindFirstChild("Humanoid") ~= player.Character.Humanoid then 
				local hum = hit.Parent:FindFirstChild("Humanoid")
				hum:TakeDamage(5)
		print("Hello")
		print(hit.Parent:FindFirstChild("Humanoid").Parent)
	end
	end
end
end
end
end
script.Parent.Touched:Connect(ontouch)

This discussion is preserved as it was. New answers, comments, and votes are closed.