Bullet won't hurt a player?
Asked by
5 years ago Edited 5 years ago
I have a gun that I have been scripting and building from scratch but I have come to a problem when trying to make it do damage. This is my gun code witch works fine.
01 | local player = game:GetService( "Players" ).LocalPlayer |
02 | local mouse = player:GetMouse() |
03 | local tool = script.Parent |
05 | tool.Activated:Connect( function () |
07 | local bullet = Instance.new( "Part" ) |
09 | bullet.Size = Vector 3. new( 0.27 , 0.25 , 1.49 ) |
11 | bullet.Anchored = false |
13 | bullet.CanCollide = true |
15 | bullet.BrickColor = BrickColor.new( "Really red" ) |
17 | bullet.Material = Enum.Material.Neon |
19 | bullet.Parent = workspace |
21 | bullet.Position = tool.Handle.Position + Vector 3. new( 0 , 0.5 , 0 ) |
23 | bullet.CFrame = CFrame.new(bullet.CFrame.p, mouse.Hit.p) |
26 | local hurt = script.Parent.Hurt:Clone() |
30 | local TweenService = game:GetService( "TweenService" ) |
32 | local info = TweenInfo.new( 3 , Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0 , false , 0 ) |
34 | local tween = TweenService:Create(bullet, info, { Position = bullet.CFrame.lookVector * 1000 } ) |
36 | tween.Completed:Connect( function () |
Then this "hurt" script when cloned gets activated but does nothing upon collisions with players or dummies or objects. Here is the script.
1 | script.Parent.Touched:Connect( function (hit) |
3 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
4 | hit.Parent.Humanoid.Health.Value = hit.Parent.Humanoid.Health.Value - 15 |
here is an image of the location of things:
https://ibb.co/93B3Cch