Backpack script not working

I tried to make this Backpack system but it’s not working no errors also this is the script

local plr = game.Players.LocalPlayer

script.AddHydration.OnServerEvent:Connect(function(player)
	if player.leaderstats.Hydration.Value == script.Capacity.Value then
		player.leaderstats.Hydration.Value = player.leaderstats.Hydration.Value + 0 * (player.leaderstats.Rebirths.Value + 1)
	else if player.leaderstats.Hydration.Value < script.Capacity.Value then
			player.leaderstats.Hydration.Value = player.leaderstats.Hydration.Value + 5 * (player.leaderstats.Rebirths.Value + 1)
		end
	end
end)

What could be the problem?

“else if” should be “elseif” instead. Is this a server script or a local script since “game.Players.LocalPlayer” is only valid in local scripts.

Also here:

+ 0 * (player.leaderstats.Rebirths.Value + 1)

Anything multiplied by 0 is 0 so this is pointless.

it is a local script, fine let me check if it works

Nope that did not work it’s still exceeding 10 hydration

if the script in local script change OnServerEvent to OnClientEvent

What I want the script to do is when it exceeds the Capacity value (which is 10) then it should add 0 to the hydration if not it should add +5

Uhh, I don’t know if I’m correct or not but are you putting a RemoteEvent in a local script :)?

make sure it is on normal script

script.AddHydration.OnServerEvent:Connect(function(player)
	if player.leaderstats.Hydration.Value == script.Capacity.Value then
local num = (player.leaderstats.Hydration.Value)..0
		player.leaderstats.Hydration.Value =  num * (player.leaderstats.Rebirths.Value + 1)
	else if player.leaderstats.Hydration.Value < script.Capacity.Value then
			player.leaderstats.Hydration.Value = player.leaderstats.Hydration.Value + 5 * (player.leaderstats.Rebirths.Value + 1)
		end
	end
end)

I’m so sorry it’s just a normal script not a local script by the way

Will this work in a normal script also?

if AddHydration changing from normal script this will work fine if it change from local script it wont work

you are useing

and

onserverevents first parameter is the player

Uhm so what changes should I do exactly?

yes is it wrong to use it or should we use any other commands

can i get more info about AddHydration

Uhm it’s just a RemoteEvent and nothing else inside it

imean how you fire it im sure there is something or try to print something whene it fires

what local plr does?
im not that good but maybe u should try replacing player with plr

if it’s a remote event then you should not be calling the event on the client. You should be calling the event from the server. Also if you update the value on the client it will not replicate to the server.

If this is a script then I don’t see anything wrong besides the fact that game.Players.LocalPlayer will only return a nil value.