Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Subtracting from IntValue makes it negative?

Asked by
trapiz 4
5 years ago
Edited 5 years ago

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

Log in to vote
0
Answered by 5 years ago

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

0
Ah okay, I figured that doing it on the client was the problem. Thanks! trapiz 4 — 5y
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. trapiz 4 — 5y
Ad

Answer this question