Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Subtracting from IntValue makes it negative?

I'm making a stamina intvalue so when you swing a sword it subtracts a certain amount of stamina from the value. This is a local script under the sword tool.

script.Parent.Activated:Connect(function()
	Stamina = Stamina - 30

	wait(.9)
	print(Stamina)
end)

It says -30 in the output. Why does this happen?

1 answer

✓ Accepted answer

That Stamina Int Value must be equal to 0. Thats why It's being substracted, if not Your probably doing something client side and server side. which aren't supposed to be happening.

I'm assuming that its appearing as -30 because in the server it's (The actual number of the value) but your substracting it in the client. So you'll have to substract in the server:

Local Script

local Remote = Instance.new("RemoteEvent")
Remote.Parent = game.ReplicatedStorage


script.Parent.Activated:Connect(function()
    Remote:FireServer(Stamina)

    wait(.9)
    print(Stamina)
end)

Server Script

game.ReplicatedSotrage.OnServerEvent:Connect(function(Player,Stamina)
        Stamina = Stamina - 30
end)

There may be some problems and you'll need to adjust it to work with your script.

Put the server script inside of serverscriptservice

2 comments

0

Ah okay, I figured that doing it on the client was the problem. Thanks!

0

Okay, so for some reason if I have the Server Script in ServerScriptService it just says "StaminaScript is not a valid member of ServerScriptService", however if I put the script in Workspace it works but when I swing the sword it prints "0", but it should be 70 since I only want it to subtract 30.

This discussion is preserved as it was. New answers, comments, and votes are closed.