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

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

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

✓ Accepted answer

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)

1 comment

0

Sorry for the late acceptance of the answer, kind of forgot about this question

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