i'm trying to make the player when press key f he will do the throwing animation and then throw a fire ball and it will deal damage to what it hits, and it worked but there's a problem sometime it doesn't damage at all and specially when i'm walking and throwing at the same time it doesn't deal damage at all , i tried to make the ball smaller and it actually worked the ball damaged normally as i want it but when the fireball size was big it didn't damage , i start testing and i think that's when the ball hit more than one thing (part) the script work normally and the ball deal damage but when the ball was big it was hitting more than one thing (part) at once and that what stopped it from dealing damage , i think that the problem but please check my code and help me.
1) Local Script inside (StarterPack) : local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local RemoteEvent = game.Workspace.remoteEvents.fireLine local RemoteEvent2 = game.Workspace.remoteEvents.fireLine2 local UIS = game:GetService("UserInputService") local Debounce = false UIS.InputBegan:connect(function(Input,mouse, x, y, z) local char = Player.Character if Input.KeyCode == Enum.KeyCode.F then --wait(1) if Debounce == true then return end Debounce = true if script.level.Value == 1 then local roll = Instance.new("Animation") roll.AnimationId = "http://www.roblox.com/asset/?id=2393690494" local animloader = char.Humanoid:LoadAnimation(roll) animloader:Play() wait(0.8) mouse = Mouse.Hit x = Mouse.Hit.p.x y = Mouse.Hit.p.y z = Mouse.Hit.p.z RemoteEvent:FireServer(mouse, x, y, z) end if script.level.Value == 2 then mouse = Mouse.Hit x = Mouse.Hit.p.x y = Mouse.Hit.p.y z = Mouse.Hit.p.z RemoteEvent2:FireServer(mouse, x, y, z) end wait(1) Debounce = false end end) 2) Script inside (Workspace) : Instance.new("BodyPosition", workspace) game.Workspace.remoteEvents.fireLine.OnServerEvent:Connect(function(Player,mouse, x, y, z) local AlreadyTouched = false local Character = Player.Character or Player.CharacterAdded:wait() local FireLine = game.ReplicatedStorage.Kai.FireLine:Clone() FireLine.CanCollide = false FireLine.Parent = Character FireLine.CFrame = Character.HumanoidRootPart.CFrame*CFrame.new(-1.5,1,-3) local BV = Instance.new("BodyVelocity") BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge) BV.Velocity = (FireLine.Position - mouse.p).unit * -175 BV.Parent = FireLine FireLine.Touched:Connect(function(Hit) local Humanoid = Hit.Parent:FindFirstChild("Humanoid") --if Humanoid == nil then Humanoid = Hit.Parent.Parent:FindFirstChild("Humanoid") end print(Hit.Name) --print("Hit.Parent.Parent: " , Hit) if Humanoid == nil and Hit.Name ~= "Terrain" then FireLine:Destroy() end if AlreadyTouched == false and Hit.Name ~= "Terrain" then AlreadyTouched = true if Humanoid.Parent.Name == Player.Name then Humanoid.Health = Humanoid.Health else Humanoid.Health = Humanoid.Health - Humanoid.MaxHealth/4 FireLine:Destroy() end end end) wait(2) FireLine:Destroy() end)
The problem is that the ball touched not only your character, but also your accessories.
In the script inside Workspace, when the fire ball touches a part, it fires. However, it came from your character, so it will touch your character first. However, it also touch the Handle of your accessories, causing it to find the Humanoid in its parent, which is the Accessory, not the character. Therefore, it couldn't find the Humanoid, thus destroying itself.
Here's a quick fix for you: Use the function Instance:IsDescendantOf(). This will check if the touched part is the descendant (instead of an immediate child) of an Instance, and in this case, your character.
--Script inside Workspace, FireLine.Touched event FireLine.Touched:Connect(function(Hit) if Hit:IsDescendantOf(Character) then --if Hit is anywhere inside the Player's character, ignore return end local Humanoid = Hit.Parent:FindFirstChild("Humanoid") print(Hit.Name) --Ever wonder why it printed out "Handle" all the time? Now it's solved. if Humanoid == nil and Hit.Name ~= "Terrain" then FireLine:Destroy() else --instead of "end" since this will continue the thread and therefore returns an error if AlreadyTouched == false and Hit.Name ~= "Terrain" then AlreadyTouched = true if Humanoid.Parent.Name ~= Player.Name then --is this the player? --no? take damage. Humanoid.Health = Humanoid.Health - Humanoid.MaxHealth/4 FireLine:Destroy() end end end end)