Server does not change IntValue when returned to client

Hello everyone,
I am currently trying to make a gun system with a reload system.
The client basically sends the current IntValues in the gun (ammo = 0, maxAmmo = 2, reserve = 99) to the server when the gun has 0 ammo left.

This is what the local script looks like:

ammoRe.OnClientEvent:Connect(function(_ammo, _maxammo, _rammo)
	ammo.Value = _ammo
	maxAmmo.Value = _maxammo
	rAmmo.Value = _rammo
	AmmoGui.Main.AmmoLabel.Text = rAmmo.Value
end)

A server script in the gun then picks the FireServer of the client up and gets the values. It then compares the ammo and maxAmmo and substracts the needed amount from the reserveAmmo and sends it back to the client, but only the reserveAmmo still stays at 99.

This is the server script:

local function onRl(plr)
	local amount = 0
	local need = maxAmmo.Value - ammo.Value
	
	if rAmmo.Value > need then
		amount = need
	else
		amount = maxAmmo.Value
	end
	
	ammo.Value += amount
	rAmmo.Value -= amount

	rl:FireClient(plr, ammo.Value, maxAmmo.Value, rAmmo.Value)
end

rl.OnServerEvent:Connect(onRl)

I tried to put the IntValues in a configuration, or to just put them in the Gun Tool, but it did not work. Does someone has a solution to this problem?

Thanks!

You can’t do any manipulations from the client over the IntValue (as i remember)

Yea that is true, but the server should actualy change the reserve Value, but it does not for whatever reason even though it does change the ammo Value.

maybe you can try to convert intvalue’s value via tonumber() and then send it to client
(idk how it’s related to the issue, just try lmao)

Tried it, did not work :confused:
I also tried tostring(IntValue.Value), but did also not work

are you sure you’re sending right remote?
image
image

rl is a local for the same remoteEvent I fired (didn’t mention the locals, sorry)

Im gonna try to find a article to help, in the meantime try changing the remote events to a remote function. This might not (probably wont) solve the issue but it will help with debugging and script efficiency.

I remember this as well from when I was beginning. Try adding print functions to find where the exact error is.

1 Like

Sorry :sweat_smile:, I checked out my local script and tried to set the ammo.Value over the client instead of server…
Thanks for your help, I would never figured this out that the client can’t change IntValues.

1 Like