You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Make a gun that fires a part called bullet. The bullet comes from the handle and is aimed at the mouse direction.
-
What is the issue? I keep getting the error “ServerScriptService.ShootReceiver:20: attempt to perform arithmetic (sub) on Instance and Vector3”
If you need the client script please let me know as im new to posting on devforum.
-- VARIABLES --
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Shoot = ReplicatedStorage:WaitForChild("Shoot")
local gun = game.Workspace:WaitForChild("Glock")
local bullet = ReplicatedStorage:WaitForChild("Bullet")
local handle = gun:WaitForChild("Handle").Position
local ExitPoint = gun:WaitForChild("ExitPoint").Position
-- MAIN --
Shoot.OnServerEvent:Connect(function(mousepos)
local bulletSpeed = 500
local GBullet = bullet:Clone()
GBullet.Parent = game.Workspace
print("Bullet is in workspace")
-- Calculate the bullet's initial position based on the ExitPoint and direction
GBullet.CFrame = CFrame.new(handle, Vector3.new(mousepos))
local bulletDir = CFrame.new(Vector3.new(mousepos - ExitPoint))
GBullet.Velocity = bulletDir * bulletSpeed
print("Gun Fired")
Shoot:FireClient(mousepos)
end)