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)