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

How do I save a NumberValue's Value on Death?

Asked by 8 years ago

A little explaining on what I'm working on:

I'm constructing a money system for my game. Every time money is put into the NumberValue there is a GUI that changes values in response of change in the NumberValue's value. Always setting the GUI's text to the value of the NumberValue.

Due to complications I had to put the NumberValue in the character model of the player, but the problem with that every time the player dies the value gets changed back to 0. Making them lose all their money. Below, there is the script I tried to combat that problem. It didn't work:

wait(5)
BeliV = game.Players.LocalPlayer.Character.BeliV
DeadMoney = BeliV.Value

function IDie()
    DeadMoney = game.Players.LocalPlayer.Character.BeliV.Value -- Puts all money into variable DeadMoney
    wait(10) -- A small wait for you to respawn
print("We made it here") -- It's not getting past the wait(10)

BeliV.Value = BeliV.Value + DeadMoney   
end


game.Players.LocalPlayer.Character.Humanoid.Died:connect(IDie)

BeliV is the name of the NumberValue and the variable for it as well. I'll show you the OTHER script that handles dishing out money to the player:

S = script.Parent
Beli = script.Parent.Beli
local BeliV = Instance.new("NumberValue", game.Players.LocalPlayer.Character)
Ching = Instance.new("Sound" , BeliV)
BeliV.Name = "BeliV"
DeadMoney = 0
function GainingMoney()
    script.Parent.Beli.Text = tostring(BeliV.Value .."$")
    S.ChaChing:Play()
end



BeliV.Changed:connect(GainingMoney)

while wait(300) do
    BeliV.Value = BeliV.Value + 250
    Beli.Text = BeliV.Value .. "$"
    S.ChaChing:Play()

end

What I'm really trying to figure out is how would I save the value of the NumberValue so when they die they can keep their money? I'm trying to avoid moving anything around as much as possible, but if I have to...

If you're confused about something, comment so I can explain in detail.

Thanks for the help!

1 answer

Log in to vote
0
Answered by 8 years ago

Alright now instead of having the number value in the players character save it in a folder in replicated storage. Have this in a server script

game.Players.PlayerAdded:connect(funtion(plr)
local folder = Instance.new("Folder", game.ReplicatedStorage)
folder.Name = plr.Name .. "'s Folder"
local num = Instance.new("NumberValue",folder)
end)

Then have in a local script get the value from the replicated storage and do whatever you want with it honestly :/

0
Ok, I understand what you're doing here, but after it's put into the Replicated Storage, how do I reach THAT players folder. RadioactiveP0P 44 — 8y
0
Alright so in a local script do local plr = game.Players.LocalPlayer local numberValue = game.ReplicatedStorage:FindFirstChild(plr.Name .. "'s Folder").Value.Value Angels_Develop 52 — 8y
Ad

Answer this question