local replicatedstorage = game:GetService("ReplicatedStorage")
local remoteevent = replicatedstorage:WaitForChild("ShotEvent")
remoteevent.OnServerEvent:Connect(function(player, gunpos, moupos)
local bullet = Instance.new("Part")
bullet.Name = "Bullet"
bullet.Parent = game.Workspace
bullet.Position = gunpos
local distance = (moupos - gunpos).magnitude
local speed = 500
bullet.CFrame = CFrame.new(gunpos, moupos)
bullet.Velocity = bullet.CFrame.lookVector * speed
end)
up there is code but i understand everything except this part(i understand "local speed = 500")
local distance = (moupos - gunpos).magnitude
local speed = 500
bullet.CFrame = CFrame.new(gunpos, moupos)
bullet.Velocity = bullet.CFrame.lookVector * speed

4 comments
assuming the parameter moupos is mouse position and gunpos is the gun position, .Magnitude converts 2 positions into a number (aka distance away from each other), bullet.CFrame on line 3 sets the position of the bullet to the gun while the rotation is towards the mouse, the bullet then shoots on line 4, shoots in the direction at a certain speed.
thank you, and how can i mark you as solution?
You can only mark answers as solutions, you can add [ANSWERED] to the title
ok thanks