Intro
Hello DevForums. I’m trying to make a part that makes you take damage continuously whilst a player’s character is in it. I’ve searched through countless solutions to this, but none of them have worked.
What’s supposed to happen:
A user creates a part in which other players that are inside take damage.
…
And no. There is no output because this is about the hit detection.
I’m using the Zone Plus module by @ForeverHD
CODE
local Zone = require(game:GetService("ServerStorage"):WaitForChild("Zone", math.huge))
local DAMAGE = 10;
local INTERVAL = 0.5;
Tool.Ability.OnServerEvent:Connect(function(Player)
if not AbilityDebounce and Tool.Parent == Player.Character and Player.Character and Player.Character:FindFirstChild("HumanoidRootPart") and not Player.Character.Lobby.Value then
AbilityDebounce = true;
local Disco = game:GetService("ServerStorage").Effects.Fart:Clone()
Disco.Size = Vector3.new(0.1,0.1,0.1)
Disco.Position = Player.Character.HumanoidRootPart.Position
Disco.Value.Value = Player.Name
Disco.Parent = workspace
--Disco.Script.Enabled = true;
Disco["fart meme"]:Play()
game:GetService("Debris"):AddItem(Disco, 5)
task.delay(AbilityTime, function()
AbilityDebounce = false;
end)
local Region = Zone.new(Disco)
local touchingHumanoids = {}
Region.playerEntered:Connect(function(player)
print(player.Name)
if player.Character and player.Character:FindFirstChild("Humanoid") and not player.Character.Lobby.Value then
local Character = player.Character
if Character.Name ~= Disco.Value.Value then
table.insert(touchingHumanoids, Character:FindFirstChild("Humanoid"))
end
end
end)
Region.playerExited:Connect(function(player)
if player.Character and player.Character:FindFirstChild("Humanoid") and table.find(touchingHumanoids, player.Character:FindFirstChild("Humanoid")) then
local Character = player.Character
touchingHumanoids[table.find(touchingHumanoids, Character:FindFirstChild("Humanoid"))] = nil;
end
end)
task.spawn(function()
while true do
for i, humanoid in ipairs(touchingHumanoids) do
if humanoid and humanoid.Health > 0 then
humanoid:TakeDamage(DAMAGE)
local Attachment = Instance.new("Attachment")
Attachment.Parent = script.Parent
Attachment.WorldPosition = humanoid.Parent.HumanoidRootPart.Position
local Hit = script.Parent.Hit:Clone()
Hit.Parent = script.Parent
Hit:Play()
game:GetService("Debris"):AddItem(Hit, 0.5)
game:GetService("Debris"):AddItem(Attachment, 1)
end
end
task.wait(INTERVAL)
end
end)
end
end)
OUTPUT
When printing out what is detected, only the player who created the part is detected. Other players that are inside the part aren’t detected at all. The script is done on the server so this shouldn’t be happening.
VVV
Funny enough though… if I have the part pre-created in workspace before play testing the game, and not created by the script… it does what is intended.