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

IntValue's Value not changing in Script when supposed to, any help?

Asked by
stef0206 125
4 years ago

So I'm making a stat system where certain stuff give you buffs, in this example the player gets a buff to the stat "Speed"

function ChangeStat(char, Stat, amount)
    game.Workspace.Data[char.Name][Stat].Value = amount + 1
    print(workspace.Data[char.Name][Stat].Name.." "..workspace.Data[char.Name][Stat].Value)
end

ChangeStat(char, "Speed", -.05)

I've confirmed it locates the IntValue correctly, and if I print amount I get the correct output, but when I print the stat's Value after it should've been changed I always recieve whatever it was before, in this case 1 when it should be 0.95.

I could really use some help on this as it really confuses me. Thank you in advance!

1 answer

Log in to vote
1
Answered by
Lakodex 711 Moderation Voter
4 years ago

You Don't Do

game.Workspace.Data[char.Name][Stat].Value = amount + 1

You do

game.Workspace.Data[char.Name][Stat].Value = game.Workspace.Data[char.Name][Stat].Value + amount

Fixed Script

function ChangeStat(char, Stat, amount)
    game.Workspace.Data[char.Name][Stat].Value = game.Workspace.Data[char.Name][Stat].Value + amount
    print(workspace.Data[char.Name][Stat].Name.." "..workspace.Data[char.Name][Stat].Value)
end

ChangeStat(char, "Speed", -.05)
0
Sorry for the late acceptance of the answer, kind of forgot about this question stef0206 125 — 3y
Ad

Answer this question