I have created a script that clones a part called "Damager" onto a hitbox. Damager should damage everything it touches, however for some reason it is not dealing damage when it is cloned. This is the script in damager:
function onTouched(hit) local human = hit.Parent:findFirstChild("Humanoid") if (human ~= nil) then human.Health = human.Health - 2 -- Change the amount to change the damage. end end script.Parent.Touched:connect(onTouched)
It should work. This next script is the script that makes the attack work:
local player = game.Players.LocalPlayer repeat wait() until player.Character.Humanoid local humanoid = player.Character.Humanoid local mouse = player:GetMouse() local anim = Instance.new("Animation") anim.AnimationId = "http://www.roblox.com/asset/?id=4752814788" mouse.KeyDown:connect(function(key) if key == "e" then if script.Cooldown.Value == false then script.Cooldown.Value = true local playAnim = humanoid:LoadAnimation(anim) playAnim:Play() local Damage1 = workspace.Clonables.Damager:Clone() Damage1.Parent = workspace Damage1.Position = player.Character.Hitbox1.Position Damage1.Orientation = player.Character.Hitbox1.Orientation local weld1 = Instance.new("WeldConstraint") weld1.Parent = Damage1 weld1.Enabled = true weld1.Part0 = Damage1 weld1.Part1 = player.Character.Hitbox1 local Damage2 = workspace.Clonables.Damager:Clone() Damage2.Parent = workspace Damage2.Position = player.Character.Hitbox2.Position Damage2.Orientation = player.Character.Hitbox2.Orientation local weld2 = Instance.new("WeldConstraint") weld2.Parent = Damage2 weld2.Enabled = true weld2.Part0 = Damage2 weld2.Part1 = player.Character.Hitbox2 wait (0.4) script.Cooldown.Value = false weld1:Destroy() weld2:Destroy() Damage1:Destroy() Damage2:Destroy() end end end)
In theory, all of this should work perfectly, but for some reason it is not dealing damage. Does anyone know why? Please help.
Welp, I actually dont know what is the error on your script, but i got this one that i used in my old game and it still working
--// Services local UserInputService = game:GetService('UserInputService') local ReplicatedStorage = game:GetService('ReplicatedStorage') local Players = game:GetService('Players') --// Debounces local Punching = false local Damaging = true --// Customisation local Damage = 20 local Cooldown = 0.5 --// Events local PunchEvent = ReplicatedStorage:WaitForChild('PunchEvent') --// Player local Player = game.Players.LocalPlayer local Character = game.Workspace:WaitForChild(Player.Name) local Humanoid = Character:FindFirstChildOfClass('Humanoid') local RightArm = Character:WaitForChild('Right Arm') --//Animations Punch = Instance.new('Animation') Punch.AnimationId = 'rbxassetid:// '--animation here PunchTrack = Humanoid:LoadAnimation(Punch) --// Coding UserInputService.InputBegan:Connect(function(Input) if Input.KeyCode == Enum.KeyCode.R and not Punching then Punching = true PunchTrack:Play() PunchTrack.KeyframeReached:Connect(function(Keyframe) if Keyframe == 'End' then wait(Cooldown) Punching = false Damaging = true end end) end end) RightArm.Touched:Connect(function(hitPart) if Punching and hitPart.Parent:FindFirstChild('Humanoid') and Damaging then Damaging = false local HumanoidToDamage = hitPart.Parent:FindFirstChild('Humanoid') PunchEvent:FireServer(HumanoidToDamage, Damage) end end)
ALSO.... add a RemoteEvent called "PunchEvent" (its really important that u name it PunchEvent cuz if u dont it wont work. Make this correct answer if it is
Is the damager script disabled? You have to turn disabled to false on the clone of the hitbox you make