So I have these 2 different scripts. The server script is supposed to detect when a player touches the part, and fires the event which is supposed to refill the player’s ammo. I don’t know what could be wrong with it to make it not work.
Server script:
local Players = game:GetService("Players")
local part = script.Parent
local function onTouched(part)
local player = Players:GetPlayerFromCharacter(part.Parent)
if not player then return end
game.ReplicatedStorage.RefillAmmo:FireClient(player)
end
part.Touched:Connect(onTouched)
local totalPossibleAmmo = 150
local totalAmmo = 150
local maxAmmo = 30
So, when the player reloads, totalAmmo -= maxAmmo. totalPossibleAmmo remembers how much ammo you could possible have so when you refill ammo, it sets it to that.