Ie_fishe
(paywalls)
#1
I’ve made this short projectile based gun but for some reason the bullet just flies to the center of the world, I have no clue why this is happening.
Server:
local Remotes = game.ReplicatedStorage.GunEvents
local Shoot = Remotes.Shoot
local IgnoreTable = {
game.Workspace.Bullets;
}
Shoot.OnServerEvent:Connect(function(plr, Barrel, Stat, Handle, MousePos, MouseCFrame)
local BarrelPos = Barrel.Position
print(plr.Character)
local Hit, Pos = game.Workspace:FindPartOnRayWithIgnoreList(Ray.new(plr.Character.Head.Position, (MousePos - plr.Character.Head.Position)), {plr.Character})
local Bullet = game.ReplicatedStorage.Bullet:Clone()
Bullet.CFrame = CFrame.new(BarrelPos, Pos) * CFrame.new(0, 0, -2);
local bv = Instance.new("BodyVelocity", Bullet)
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = MouseCFrame.LookVector * 1;
Bullet.Parent = game.Workspace.Bullets
end)
Client:
local Stat = {
Damage = 10;
Spread = 5;
Mode = 'Auto';
}
script.Parent.Equipped:Connect(function()
Hold:Play()
end)
script.Parent.Activated:Connect(function()
Hold:Stop()
Aim:Play()
Aim.Stopped:wait()
Aimed:Play()
Shoot:FireServer(Barrel, Stat, Handle, MousePos, MouseCFrame)
end)
Some passed on variables are defined, they just are self explanatory.
2 Likes
Is the mousePos mouse.hit.p or is it the cframe one?
Operatik
(Operatik)
#3
I believe you haven’t fired the proper parameter to the server, which is the MousePos
. Replace that with the aforementioned statement: mouse.Hit.p
Ie_fishe
(paywalls)
#4
this is my mouse pos stuff
local plr = game.Players.LocalPlayer
local Mouse = plr:GetMouse()
local MousePos = Mouse.Hit.p
local MouseCFrame = Mouse.Hit
Mouse.Hit
is the position where the mouse is hitting, not the direction, you should instead use Bullet.CFrame.LookVector
Ie_fishe
(paywalls)
#6
Would I replace the part where I set bullet’s CFrame with this
No, the part where you do bv.Velocity
Ie_fishe
(paywalls)
#8
But the bullet velocity is working it just faces wrong direction
Yeah I know set it to bv.Velocity = Bullet.CFrame.LookVector * Velocity
Replace Velocity
with a velocity for your bullet
Ie_fishe
(paywalls)
#10
Shoot.OnServerEvent:Connect(function(plr, Barrel, Stat, Handle, MousePos, MouseCFrame)
local BarrelPos = Barrel.Position
print(plr.Character)
local Hit, Pos = game.Workspace:FindPartOnRayWithIgnoreList(Ray.new(plr.Character.Head.Position, (MousePos - plr.Character.Head.Position)), {plr.Character})
local Bullet = game.ReplicatedStorage.Bullet:Clone()
Bullet.CFrame = CFrame.new(BarrelPos, MouseCFrame.Position);
local bv = Instance.new("BodyVelocity", Bullet)
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = MouseCFrame.LookVector * 1;
Bullet.Parent = game.Workspace.Bullets
end)
Ie_fishe
(paywalls)
#12
Fixed it, issue was I defined the mouse position early in the script meaning it stayed constant
1 Like