Pistol not shooting when activated?

I’m trying to make a pistol for a game, but whenever I test it, it doesn’t shoot, and gives the error 13:23:58.693 - Cframe is not a valid member of Part and the ‘Part’ is the ShootPart.

Here is the script for it

local Pistol = script.Parent.Parent.Parent
local Values = Pistol.Handle.Values
local range = Values.Range
local Damage = Values.Damage
local ShootSpeed = Values.ShootSpeed
local AllowTracing = Values.AllowTracing
local debounce = true
local plr = game.Players.LocalPlayer
local ShootPart = Pistol.Handle.ShootPart
Pistol.Equipped:Connect(function()
	Pistol.Activated:Connect(function(mouse)
		if debounce then --No spamming
			debounce = false
			local ray = Ray.new(ShootPart.Cframe.p (mouse.Hit.p - ShootPart.Cframe) * range.Value)
			local hit, position = workspace:FindPartOnRay(ray, plr.character, false, true)
			
			if AllowTracing == true then
				local Trace = Instance.new("Part", workspace)
				Trace.Material = Enum.Material.Neon
				Trace.BrickColor = BrickColor.new("Black")
				Trace.CanCollide = false
				Trace.Anchored = true
				Trace.Transparency = 0.5
				
				local Distance = (ShootPart.Cframe.p - position).magnitude
				Trace.Size = Vector3.new(0.2,0.2,Distance)
				Trace.CFrame = CFrame.new(ShootPart.Cframe.p, position) * CFrame.new(0,0, -Distance/2)
				
				game:GetService("Debris"):AddItem(Trace, 0.1)
			end
			if hit then
				local Humanoid = hit.Parent:FindFirstChild("humanoid")
				if Humanoid then
					Humanoid:TakeDamage(Damage.Value)
				end
			end
			wait(ShootSpeed.Value)
			debounce = true
		end
	end)
end)
Trace.CFrame = CFrame.new(ShootPart.CFrame.p, position) * CFrame.new(0,0, -Distance/2)

U used ‘Cframe’ instead of ‘CFrame’

1 Like

It’s CFrame, not Cframe, that’s the reason you’re getting the error.

1 Like

Then i get the error 13:30:25.528 - Players.SadWowow21.Backpack.Pistol.Handle.Scripts.Script:14: attempt to index nil with ‘Hit’

I tried searching up yt tutorials for this but none worked

Bruh, you haven’t even defined ‘mouse’. Can you like, double check the errors your debugger shows before testing.

just defined mouse as

local mouse = game.Players.LocalPlayer:GetMouse()

Also, can u fix the Cframe to CFrame too

1 Like

Oh sorry, in the tutorial I was watching they didn’t define mouse either

Also a little tip, if you use this in a local script:

it won’t replicate in the server meaning, your pistol won’t do any damage to the player, you need to create a remote event and fire it in a server script, with the code you wrote, so that the player can actually take the damage

1 Like