This is a script in ServerScriptService, so when the player dies, it gives the player the in-game currency.
THE PROBLEM
Although it prints out everything (with no error), It doesn’t change any values. It does print out what it’s supposed to give.
HAVE I LOOKED FOR SOLUTIONS? (NO)
I don’t know what to search.
PLEASE HELP!
--[[
Coments. 20 Comets : 1 Koi. If Comets are not exactly a 20 multiple, then it will be rounded to the nearest
twenty. If it's not convertable, then it will be rounded down.]]
game.Players.PlayerAdded:Connect(function(plr)
while true do wait()
if plr.Character then break end
end
local hum = plr.Character:WaitForChild("Humanoid")
hum.Died:Connect(function()
local CometsValue = plr.leaderstats.Comets.Value
local KoiValue = plr.leaderstats.Koi.Value
print(plr.Name.." has died! Rewards and others are being given")
local RewardsUncalc = CometsValue/20
local NowRewards = math.floor(RewardsUncalc)
print(plr.Name.." will get "..NowRewards.." Koi!")
-- print(KoiValue + NowRewards)
KoiValue = KoiValue + NowRewards
CometsValue = 0
print("Rewards Given!")
end)
end)
You’re changing your variable, not the actual .Value. This happens because when you made the variable, it just stores a number, not an actual reference to .Value.
Code:
--[[
Coments. 20 Comets : 1 Koi. If Comets are not exactly a 20 multiple, then it will be rounded to the nearest
twenty. If it's not convertable, then it will be rounded down.]]
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = plr:WaitForChild("leaderstats")
local Comets = leaderstats:WaitForChild("Comets")
local Koi = leaderstats:WaitForChild("Koi")
plr.CharacterAdded:Connect(function(character)
local hum = character:WaitForChild("Humanoid")
hum.Died:Connect(function()
print(plr.Name.." has died! Rewards and others are being given")
local RewardsUncalc = Comets.Value/20
local NowRewards = math.floor(RewardsUncalc)
print(plr.Name.." will get "..NowRewards.." Koi!")
-- print(KoiValue + NowRewards)
Koi.Value += NowRewards
Comets.Value = 0
print("Rewards Given!")
end)
end)
end)
You could also use .CharacterAdded instead of a loop.