Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Bullet won't hurt a player?

Asked by 4 years ago
Edited 4 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.

local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent

tool.Activated:Connect(function()
    --Set Up
    local bullet = Instance.new("Part")
    --Size
    bullet.Size = Vector3.new(0.27,0.25,1.49)
    --Anchored
    bullet.Anchored = false
    --Can/Can Not Collide
    bullet.CanCollide = true
    --Color
    bullet.BrickColor = BrickColor.new("Really red")
    --Matirial
    bullet.Material = Enum.Material.Neon
    --Parent
    bullet.Parent = workspace
    --Positon
    bullet.Position = tool.Handle.Position + Vector3.new(0,0.5,0)
    --Angle
    bullet.CFrame = CFrame.new(bullet.CFrame.p, mouse.Hit.p)

    --Hurt
    local hurt = script.Parent.Hurt:Clone()
    hurt.Parent = bullet
    hurt.Disabled = false
    --Movement
    local TweenService = game:GetService("TweenService")

    local info = TweenInfo.new(3, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)

    local tween = TweenService:Create(bullet, info, {Position = bullet.CFrame.lookVector * 1000})
    tween:Play()
    tween.Completed:Connect(function()
        bullet:Destroy()
    end)
end)

Then this "hurt" script when cloned gets activated but does nothing upon collisions with players or dummies or objects. Here is the script.

script.Parent.Touched:Connect(function(hit)
    print(hit.Parent)
    if hit.Parent:FindFirstChild("Humanoid") then
        hit.Parent.Humanoid.Health.Value = hit.Parent.Humanoid.Health.Value - 15
    end
end)

here is an image of the location of things:

https://ibb.co/93B3Cch

0
JUST relized it does not print? aandmprogameing 52 — 4y
0
JUST relized it does not print? aandmprogameing 52 — 4y

1 answer

Log in to vote
0
Answered by
Alphexus 498 Moderation Voter
4 years ago

There is no value.

0
? aandmprogameing 52 — 4y
0
I need more info then that aandmprogameing 52 — 4y
0
No .Value in Health. Just remove .Value Alphexus 498 — 4y
0
did not work aandmprogameing 52 — 4y
0
did not work aandmprogameing 52 — 4y
Ad

Answer this question