I'm making tools in my game that can be upgraded by pressing r which takes money for the upgrade. I've been doing tests with the print function after every "if" and it's all working flawlessly but for some reason when I print the cash it always shows as 0 even when it isnt. (both in game and in studio) Please help. scripts below:
local script in tool:
repeat wait() until game.Players.LocalPlayer.Character
local Player = game.Players.LocalPlayer
local Body = Player.Character
local Mouse = Player:GetMouse()
local Level = script.Parent.Level.Value
local Cash = Player.leaderstats.Cash.Value
script.Parent.Activated:connect(function()
local Destination = Mouse.Hit
wait(5 - Level)
Body:MoveTo(Destination.p)
end)
Mouse.KeyDown:connect(function(k)
k = k:lower()
if k == "r" then
if Level < 5 then
if Cash >= (Level * 5) then
Level = Level + 1
Cash = Cash - (Level * 5)
end
end
end
end)
script that creates leaderboard: (works)
game.Players.PlayerAdded:connect(function(Player)
local Statistics = Instance.new("Folder",Player)
Statistics.Name = "leaderstats"
local Cash = Instance.new("IntValue",Statistics)
Cash.Name = "Cash"
Cash.Value = 0
end)
script that makes an increase to leaderboard: (works)
Increment = 1
Interval = 5
Economy = "Cash"
while true do
wait(Interval)
for i,v in pairs(game.Players:GetPlayers()) do
if v:FindFirstChild("leaderstats") and v then
v.leaderstats[Economy].Value = v.leaderstats[Economy].Value + Increment
end
end
end

1 comment
btw filtering is disabled.