I have this script, it only damages one player, how can i make it damage multiple npcs, and players?
local Hits = {}
Part.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
if Hits[Hit.Parent.Name] then
return
end
Hits[Hit.Parent.Name] = true
Hit.Parent.Humanoid:TakeDamage(5)
end
end)
EDIT: better explanations
I am trying to achieve something that damages every player that touches the part, not just one. Currently, it only damages one player. I want it to damage everyone it touches, even if it touches more than one player. Sorry if i was unclear
local Hits = {}
local Part = script.Parent
Part.Touched:Connect(function(Hit)
if Hit and Hit.Parent then
local player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if player then
player.Character.Humanoid:TakeDamage(5)
end
end
end)
I think youre trying to make a debounce
to each player touches the part to avoid spam
local Hits = {}
Part.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
if Hits[Hit.Parent.Name] then
return
end
Hits[Hit.Parent.Name] = true
Hit.Parent.Humanoid:TakeDamage(5)
wait(2) -- to take damage again
Hits[Hit.Parent.Name] = false
end
end)
you just forgot to set back each of the player’s boolean
I am trying to achieve something that damages every player that touches the part, not just one. Currently, it only damages one player. I want it to damage everyone it touches, even if it touches more than one player. Sorry if i was unclear
local Hits = {}
local Part = script.Parent
local debounce = false
Part.Touched:Connect(function(Hit)
if Hit and Hit.Parent then
local player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if player and debounce == false then
local debounce = true
player.Character.Humanoid:TakeDamage(5)
task.wait()
debounce = false
end
end
end)
Since constant damage is to be caused over a period of time, the touch event is not suitable for this in your case. If the player just stands on the part that is supposed to deal damage, no touch event is triggered. You should realize this dmg-scritp with the function GetPartBoundsInBox.
For example, it can give you all the humanoids in a defined part, which you can then subtract health from.
oooo, so i would do this by doing something like this?
local hits = {}
wave1.GetPartBoundsInBox:Connect(function(hit)
if hit.Parent:FindFIrstChild("Humanoid") and hit.Parent ~= char and not hits[hits.Parent] then
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(25)
hits = hits[hit.Parent]
end
end)
EDiT:
ive never used getpartsboundinbox and that website has no coding examples, so is something like that correct?