I want to make bullet hole

  1. What do you want to achieve? I want to place an image of a gun hole along the part.

  2. What is the issue? I got a error code

My script is like this.

local Players = game:GetService("Players")
local RemoteEvent = script.Parent.Shoot
local TweenService = game:GetService("TweenService")
local Bullet = script.Parent
local Damage = 10
local Range = 500
local Params = RaycastParams.new()
local GunRange = 500
local debris = game:GetService("Debris")

RemoteEvent.OnServerEvent:Connect(function(Player, MousePosition, Target, startposition, MouseHitRotation)

	local Gun = Player.Character:FindFirstChildOfClass("Tool")
	
	Gun.Handle.Sound:Play()
	
	if Gun == nil then return end

	local Direction = (MousePosition - startposition) * GunRange
	
	local RayParams = RaycastParams.new()
	RayParams.FilterDescendantsInstances = {Player.Character}
	RayParams.FilterType = Enum.RaycastFilterType.Exclude
	
	local Result = workspace:Raycast(startposition, Direction, RayParams)
	
	local Bullet = game.ReplicatedStorage.BulletAsset.Bullet:Clone()
	
	Bullet.Name = "BulletClone"
	Bullet.CFrame = Gun.Handle.CFrame + Vector3.new(10,0,0)
	Bullet.Parent = game.Workspace.Bullets
	Bullet.CFrame = CFrame.lookAt(Gun.Handle.CFrame.Position, MousePosition)
	local BulletDuration = 0.3 * ((Direction/GunRange).Magnitude)/50
	
	TweenService:Create(Bullet, TweenInfo.new(BulletDuration), {CFrame = CFrame.new(MousePosition)}):Play()
	
	Bullet.Touched:Connect(function(hitpart)
		
		local Humanoid = hitpart.Parent:FindFirstChild("Humanoid") or hitpart.Parent.Parent:FindFirstChild("Humanoid")
		
		if Humanoid then
			
			local Hole = game.ReplicatedStorage.BulletAsset.BulletHoles.BloodHole:Clone()
			Hole.Parent = game.Workspace.Bullets
			Hole.Position = MousePosition
			Hole.CFrame = CFrame.new(Hole.Position, Hole.Position * Result.Normal)
			Hole.CFrame = CFrame.LookAt(Hole.Position, Hole.Position + Result.Normal) -- error here

			local Weld = Instance.new("WeldConstraint", Hole)
			Weld.Part0 = Hole
			Weld.Part1 = hitpart
			
			debris:AddItem(Hole, 5)
			
			print("hit to humanoid")
			
			Bullet.CanTouch = false
			
			Humanoid.Health = Humanoid.Health - 10
			
			Bullet.Anchored = true
			
			Bullet.Transparency = 1
			
			Bullet:FindFirstChild("HitSound"):Play()
			
			wait(0.5)
			
			Bullet:Destroy()
			
		else
			
			local Hole = game.ReplicatedStorage.BulletAsset.BulletHoles.BulletHole:Clone()
			Hole.Parent = game.Workspace.Bullets
			Hole.Position = MousePosition
			Hole.CFrame = CFrame.new(Hole.Position, Hole.Position * Result.Normal)
			Hole.CFrame = CFrame.LookAt(Hole.Position, Hole.Position + Result.Normal) -- error here
			local Weld = Instance.new("WeldConstraint", Hole)
			Weld.Part0 = Hole
			Weld.Part1 = hitpart
			
			
			debris:AddItem(Hole, 5)

			print("Hit to part")
			
			Bullet.CanTouch = false

			Bullet.Anchored = true

			Bullet.Transparency = 1

			Bullet:FindFirstChild("HitSound"):Play()

			wait(0.5)

			Bullet:Destroy()
			
			
		end
		
	end)
	
	
	wait(3)
	
	Bullet:Destroy()
end)

So this is not along the part.
How do i fix this? I put my decal to frount side btw.

It is CFrame.lookAt not LookAt

1 Like

This is work!!

OMG THANKS VERY MUCH

1 Like

You’re welcome

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.