Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Bullet won't hurt a player?

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

2 comments

0

JUST relized it does not print?

0

JUST relized it does not print?

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.