local rs = game:GetService("ReplicatedStorage")
local gunEvent = rs:WaitForChild("GunEvent")
local gunsound = game:GetService("StarterPack")
local shootingsound = gunsound.Tool.Part.Sound
gunEvent.OnClientEvent:Connect(function(player, startPos, endPos)
shootingsound:Play()
local part = Instance.new("Part")
part.Size = Vector3.new(.25,.25,10)
part.CFrame = CFrame.new(startPos, endPos)
local bv = Instance.new("BodyVelocity", part)
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = part.CFrame.LookVector * 800
part.Parent = game.Workspace.CurrentCamera
part.CanCollide = false
part.Material = ("Neon")
part.BrickColor = BrickColor.new("New Yeller")
local function onTouch(hit)
if (hit.Parent:findFirstChild("Humanoid") ~= nil) then
print(hit)
print("Hit!")
hit.Parent.Humanoid.Health = 0
part.Touched:connect(onTouch)
delay(1, function()
part:Destroy()
end)
end
end
end)
I am having trouble with this script. I coded it so that it would print "Hit!" in the output, and it doesn't. There are no errors in the output so I am stuck on this one. How do I make it so that when a bullet hits a humanoid, it prints "Hit!"..? What am I doing wrong?
BEFORE CHANGES (original script): https://gyazo.com/f67f6219f411ac944532c7e5d099e363
AFTER CHANGES (after i attempted to make a hit detection): https://gyazo.com/5dcab6a86e787c4816e5e0c5856ea0bb

1 comment
This is not true.