I’ve got a reloading script that… reloads!
that very same script also does an “anticheat”, to prevent players from doing funny stuff
essentially, unequipping a weapon will set a boolvalue to false (on server side)
however this doesn’t necessarily seem to work, since reequipping the weapon doesn’t allow you to shoot at all (because reloading is true) (CLIENT)
but you can still trigger a reload despite it being true?
triggering a reload will fire the remote event and will trigger the anticheat, which will sadly result in you being kicked (frown)
CLIENT SCRIPT:
-- // SERVICES AND EVENTS
local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")
local ReloadEvent = RS:WaitForChild("GunEvents").ReloadEvent
local weaponStats = require(RS.ClientWeaponStats)
-- // MISC
local weapon = nil
local connection = nil
char.ChildAdded:Connect(function(child)
if not child:IsA("Tool") then return end
weapon = child
if weapon.WeaponType.Value == "GUN" then
local Shooting = weapon:WaitForChild("Shooting")
local Reloading = weapon:WaitForChild("Reloading")
local Bullets = weapon:WaitForChild("Bullets")
local Equipping = weapon:WaitForChild("Equipping")
local MAX_BULLETS = weaponStats[weapon.Name]["MAX_BULLETS"]
local Reload = weapon:WaitForChild("Reload")
local EmptyReload = weapon:WaitForChild("EmptyReload")
connection = UIS.InputBegan:Connect(function(input)
if input.UserInputType ~= Enum.UserInputType.Keyboard then return end
if input.KeyCode ~= Enum.KeyCode.R then return end
if Shooting.Value then return end
if Reloading.Value then return end
if Bullets.Value == MAX_BULLETS then return end
if Equipping.Value then return end
if Bullets.Value > 0 then
local ReloadAnim = animator:LoadAnimation(Reload)
ReloadAnim:Play()
ReloadEvent:FireServer()
else
local EmptyReloadAnim = animator:LoadAnimation(EmptyReload)
EmptyReloadAnim:Play()
ReloadEvent:FireServer()
end
end)
end
end)
char.ChildRemoved:Connect(function(child)
if not child:IsA("Tool") then return end
weapon = nil
end)
SERVER SCRIPT
local ReloadEvent = game:GetService("ReplicatedStorage"):WaitForChild("GunEvents").ReloadEvent
local gunInfo = require(game:GetService("ServerScriptService"):WaitForChild("Weapons"):WaitForChild("Gun").GunStats)
ReloadEvent.OnServerEvent:Connect(function(player)
local tool = player.Character:FindFirstChildOfClass("Tool")
local reloading = tool.Reloading
local shooting = tool.Shooting
if tool.Bullets.Value > gunInfo[tool.Name]["MAX_BULLETS"] then player:Kick("Gluttony is a sin.") return end
if tool.Equipping.Value then player:Kick("Someone's in a hurry.") return end
if shooting.Value then player:Kick("Keep trying.") return end
if reloading.Value then player:Kick("Very funny.") return end
tool.Unequipped:Connect(function()
reloading.Value = false
end)
-- // NORMAL RELOAD
if tool.Bullets.Value > 0 then
reloading.Value = true
-- the rest of the script here just reloads, doesn't set any values to true nor false (unless the reloading has finished), so i won't include it here