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

Why do my leaderstats always show as 0? (PLEASE HELP)

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

0

btw filtering is disabled.

2 answers

✓ Accepted answer

Try using .Value not in the variable?

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
local Cash = Player.leaderstats.Cash
script.Parent.Activated:connect(function()
local Destination = Mouse.Hit
wait(5 - Level.Value)
Body:MoveTo(Destination.p)
end)
Mouse.KeyDown:connect(function(k)
k = k:lower()
if k == "r" then
if Level.Value < 5 then
if Cash.Value >= (Level * 5) then
Level.Value = Level.Value + 1
Cash.Value = Cash.Value - (Level.Value * 5)
end
end
end
end)

2 comments

0

Think I already tried that, but I'll give it another shot in a moment.

0

Thank you so much! Finally works! Not even sure why it wasn't before. you're the best!!!

I would try placing the script in ServerScriptService. If is is already there try putting it in workspace. ALWAYS CAPITAL THE CONNECT! Instead of :connect try :Connect it works better and fixes errors for me.

1 comment

0

The connect isn't the issue. My key pressed function works fine. My problem is that the cash always shows as zero.

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