Im trying to make a gun and im using :ApplyImpulse to do it. When I shoot the gun I get an error in the output that says “CFrame expected, got vector3” when I change it to a CFrame it says “Vector3 expected, got CFrame”
I’ve gotten this problem many times before and this is my first time writing about it.
---ServerScript:
script.Parent.gun_fired.OnServerEvent:Connect(function(plr, mouse_POS)
print(mouse_POS)
script.Parent.Parent.SFX.Shot:Play()
local direction = script.Parent.Parent.SmokePart.Position - CFrame.new(mouse_POS)
local force = direction * Vector3.new(0, game.Workspace.Gravity / 2, 0)
local effects = script.Parent.Parent.SmokePart:GetChildren()
---Effects
for i, v in pairs(effects) do
if v.Name == "A1" or "A2" or "BEAM1" or "BEAM2" or "Weld" then
else
v.Enabled = true
end
end
task.wait(0.3)
for i, v in pairs(effects) do
if v.Name == "A1" or "A2" or "BEAM1" or "BEAM2" or "Weld" then
else
v.Enabled = false
end
end
-----------------------------
local bullet = game.ServerStorage.bullet:Clone()
bullet.Parent = workspace
bullet.Position = script.Parent.Parent.SmokePart.Position
bullet:ApplyImpulse(force * bullet.AssemblyMass)
end)
---Localscript:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local equipped = false
script.Parent.Parent.Equipped:Connect(function()
equipped = true
script.Parent.Parent.SFX.equip:Play()
print(player.Name, "Equipped their Glock")
end)
script.Parent.Parent.Unequipped:Connect(function()
equipped = false
script.Parent.Parent.SFX.unequip:Play()
print(player.Name, "unequipped their Glock")
end)
mouse.Button1Down:Connect(function()
local mouse_POS = mouse.Hit
script.Parent.gun_fired:FireServer(mouse_POS)
end)
If you have any off topic improvements, feel free to share them in the replies.
I’ve also the noticed the effects aren’t working.