Hello, I added some stuff to an old gun script, and it has some problems.
-
It’s a local script, easily exploitable to change ammo, maxammo.
-
I am not that good with the backend server so I’m having trouble doing it.
-
I’m trying to make it just the server script and completely remove the local script.
-
Local Script:
local MaxAmmo = script.Parent:WaitForChild("MaxAmmo").Value
local Ammo = script.Parent:WaitForChild("Ammo").Value
Ammo = MaxAmmo
local Reloading = false
local Mouse
local Input = game:GetService("UserInputService")
local shooting = false
local mConnect
local reloadTime = 3
local idleAnim = Instance.new("Animation", script.Parent)
idleAnim.AnimationId = "rbxassetid://"..script.Parent:GetAttribute("IdleAnimation")
IdleAnimLoad = game.Players.LocalPlayer.Character:WaitForChild("Humanoid"):LoadAnimation(idleAnim)
local shootAnim = Instance.new("Animation", script.Parent)
shootAnim.AnimationId = "rbxassetid://"..script.Parent:GetAttribute("ShootAnimation")
shootAnimLoad = game.Players.LocalPlayer.Character:WaitForChild("Humanoid"):LoadAnimation(shootAnim)
local reloadAnim = Instance.new("Animation", script.Parent)
reloadAnim.AnimationId = "rbxassetid://"..script.Parent:GetAttribute("ReloadAnim")
reloadAnimLoad = game.Players.LocalPlayer.Character:WaitForChild("Humanoid"):LoadAnimation(reloadAnim)
local CameraShaker = require(game.ReplicatedStorage.CameraShaker)
local camera = workspace.CurrentCamera
local camShake = CameraShaker.new(Enum.RenderPriority.Camera.Value, function(shakeCf)
camera.CFrame = camera.CFrame * shakeCf
end)
local function Reload()
if (Mouse)then
Reloading = true
Mouse.Icon = "rbxasset://textures/GunWaitCursor.png"
reloadAnimLoad:Play()
wait(reloadTime)
Ammo = MaxAmmo
Reloading = false
Mouse.Icon = "rbxasset://textures/GunCursor.png"
end
end
script.Parent.Equipped:Connect(function(MouseSource)
IdleAnimLoad:Play()
local function shoot()
if Ammo>0 and not Reloading then
Ammo=Ammo-1
if Mouse.Target.Parent:FindFirstChild("Humanoid") then
game.ReplicatedStorage.Ak47Shoot:FireServer(Mouse.Target.Parent, 50)
shootAnimLoad:Play()
camShake:Start()
camShake:Shake(CameraShaker.Presets.Bump)
print(Ammo)
end
end
end
Mouse = MouseSource
Mouse.Icon = "rbxasset://textures/GunCursor.png"
script.Parent:WaitForChild("IsEquipped").Value = true
local plrsMouse = game.Players.LocalPlayer:GetMouse()
mConnect = plrsMouse.Button1Down:Connect(function()
shooting = true
while shooting and script.Parent:WaitForChild("IsEquipped").Value == true do
shoot()
plrsMouse.Button1Up:Connect(function()
shooting = false
end)
wait(0.1)
end
end)
Input.InputBegan:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.R and Reloading == false and Ammo~=MaxAmmo and script.Parent.IsEquipped.Value == true then
Reload()
end
end)
end)
script.Parent.Unequipped:Connect(function(MouseSource)
script.Parent:WaitForChild("IsEquipped").Value = true
IdleAnimLoad:Stop()
mConnect:Disconnect()
end)
- Serverscript (ik its bad lol)
game.ReplicatedStorage.Ak47Shoot.OnServerEvent:Connect(function(plr, target, damage)
target.Humanoid:TakeDamage(5)
end)