Hello everyone! I’m making a top view shooting game inspired by FvMIL2. I’m mainly asking help on how I can improve my “player shooting” script.
Here’s the first part of the script:
local localPlayer = game:GetService("Players").LocalPlayer
local uis = game:GetService("UserInputService")
local shootRemote = game:GetService("ReplicatedStorage"):WaitForChild("ShootRemoteEvent")
local cooldown = false
local shootCooldown = false
local canChangeCoolDown = true
local input1 = nil
local canShootUp = false
local canShootDown = false
local canShootLeft = false
local canShootRight = false
--shootRemote:FireServer(player0, player1, velocityX, velocityZ, placementX, placementZ, orientationY) (player0 is a filler thing, fill out the stuff like it down't exists)
repeat
task.wait()
until localPlayer.Character ~= nil
uis.InputBegan:Connect(function(input0, gamePros)
if input0.KeyCode == Enum.KeyCode.Up or input0.KeyCode == Enum.KeyCode.Down or input0.KeyCode == Enum.KeyCode.Left or input0.KeyCode == Enum.KeyCode.Right then
input1 = input0.KeyCode
cooldown = false
if cooldown == false then
cooldown = true
local upHeld = uis:IsKeyDown(Enum.KeyCode.Up)
local downHeld = uis:IsKeyDown(Enum.KeyCode.Down)
local leftHeld = uis:IsKeyDown(Enum.KeyCode.Left)
local rightHeld = uis:IsKeyDown(Enum.KeyCode.Right)
if input1 == Enum.KeyCode.Up then
canShootUp = true
repeat
task.wait()
if canShootUp == true and canShootDown == false and canShootLeft == false and canShootRight == false and shootCooldown == false then
shootRemote:FireServer(localPlayer.Name, 50, 0, 0, 0, 180) -- gives players' name to shoot from, and X & Z for AssemblyLinearVelocity (X - left and right, Z - up and down)
shootCooldown = true
task.wait(0.5)
shootCooldown = false
end
upHeld = uis:IsKeyDown(Enum.KeyCode.Up)
until upHeld == false
canShootUp = false
end
if downHeld == true then
canShootDown = true
repeat
task.wait()
if canShootUp == false and canShootDown == true and canShootLeft == false and canShootRight == false and shootCooldown == false then
shootRemote:FireServer(localPlayer.Name, 50, 0, 0, 0, 0) -- gives players' name to shoot from, and X & Z for AssemblyLinearVelocity (X - left and right, Z - up and down)
shootCooldown = true
task.wait(0.5)
shootCooldown = false
end
downHeld = uis:IsKeyDown(Enum.KeyCode.Down)
until downHeld == false
canShootDown = false
end
if leftHeld == true then
canShootLeft = true
repeat
task.wait()
if canShootUp == false and canShootDown == false and canShootLeft == true and canShootRight == false and shootCooldown == false then
shootRemote:FireServer(localPlayer.Name, 50, 0, 0, 0, -90) -- gives players' name to shoot from, and X & Z for AssemblyLinearVelocity (X - left and right, Z - up and down)
shootCooldown = true
task.wait(0.5)
shootCooldown = false
end
leftHeld = uis:IsKeyDown(Enum.KeyCode.Left)
until leftHeld == false
canShootLeft = false
end
if rightHeld == true then
canShootRight = true
repeat
task.wait()
if canShootUp == false and canShootDown == false and canShootLeft == false and canShootRight == true and shootCooldown == false then
shootRemote:FireServer(localPlayer.Name, 50, 0, 0, 0, 90) -- gives players' name to shoot from, and X & Z for AssemblyLinearVelocity (X - left and right, Z - up and down)
shootCooldown = true
task.wait(0.5)
shootCooldown = false
end
rightHeld = uis:IsKeyDown(Enum.KeyCode.Right)
until rightHeld == false
canShootRight = false
end
wait(0.5)
cooldown = false
end
end
end)
The second part:
local shootRemote = game:GetService("ReplicatedStorage"):WaitForChild("ShootRemoteEvent")
shootRemote.OnServerEvent:Connect(function(player0, player1, velocityX, velocityZ, placementX, placementZ, orientationY)
local rootCFrameX = workspace:FindFirstChild(player0.Name).HumanoidRootPart.CFrame.X
local rootCFrameZ = workspace:FindFirstChild(player0.Name).HumanoidRootPart.CFrame.Z
if placementX == nil then
placementX = 0
end
if placementZ == nil then
placementZ = 0
end
if orientationY == nil then
orientationY = Vector3.new(0, 0, 0)
end
local newBullet = game:GetService("ServerStorage"):WaitForChild("Bullets").Bullet1:Clone()
newBullet.Parent = workspace.Bullets
newBullet.CFrame = CFrame.new(rootCFrameX + placementX, 1, rootCFrameZ + placementZ)
newBullet.Orientation = Vector3.new(0, orientationY, 0)
local newVectorForce = Instance.new("VectorForce")
newVectorForce.Parent = newBullet
newVectorForce.Attachment0 = newBullet.Attachment0
newVectorForce.Force = Vector3.new(velocityX, 0, 0)
end)
And the special move code:
local localPlayer = game:GetService("Players").LocalPlayer
local shootRemote = game:GetService("ReplicatedStorage"):WaitForChild("ShootRemoteEvent")
local uis = game:GetService("UserInputService")
local cooldown = false
--shootRemote:FireServer(player0, player1, velocityX, velocityZ, placementX, placementZ, orientationY) (player0 is a filler thing, fill out the stuff like it down't exists)
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Q and cooldown == false then
cooldown = true
local timesShot = 0
repeat
print("sBShot")
local orientationY = 180 + timesShot * 10
shootRemote:FireServer(localPlayer.Name, 35, 0, -0.5, nil, orientationY) -- bullet1
shootRemote:FireServer(localPlayer.Name, 35, 0, -0.5, nil, -orientationY) -- bullet2
timesShot += 1
wait(0.1)
until timesShot == 1000
cooldown = false
end
end)
Oh, and a video of how it looks it game.
robloxapp-20250327-0008319.mp3 (1012.9 KB)
Please tell me if I can improve any of the scripts, and what I have to use to make the bullets go faster. Thanks!