Nykonic
(Niels)
September 5, 2021, 12:17pm
#1
I am making a Tycoon game. So I need a leaderstat for cash.
I made this script:
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
if player then
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Cash = Instance.new("NumberValue")
Cash.Name = "Cash"
Cash.Parent = player
Cash.Value = 0
end
end)
But right now, this script isn’t adding a new folder at all into my player. Also, a leaderboard isn’t popping up. In the output, there isn’t any wrong. And also in the script does it seem right.
Please help me out!
1 Like
You made a mistake in your script.
Cash.Parent = player
The parent must be the leaderstats folder, not the player.
Nykonic
(Niels)
September 5, 2021, 12:24pm
#3
I changed it, but didnt turn out how i want. Still no leaderstats showing up
Didn’t turn out how you want? What do you mean?
Check if your playerlist is enabled. Because I replaced the parent of the Cash, tested it, and it is working as intended.
Nykonic
(Niels)
September 5, 2021, 12:32pm
#5
It’s not making an folder at all
This is a server script right?
Nykonic
(Niels)
September 5, 2021, 12:34pm
#7
Yes. ServerScriptService and a normal script. Not a Local.
Try removing the if statement at the start.
Nykonic
(Niels)
September 5, 2021, 12:36pm
#9
Still, nothing is showing up.
Maybe because the script is disabled?
Nykonic
(Niels)
September 5, 2021, 12:37pm
#11
Also, no the script is active!
solys_ui
(Solys)
September 5, 2021, 12:41pm
#12
Try this, I tested it out and it works.
You can set the instance parent as the second argument to Instance.new
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local Cash = Instance.new("IntValue", leaderstats)
Cash.Name = "Cash"
Cash.Value = 0
end)
Nykonic
(Niels)
September 5, 2021, 12:44pm
#13
solys_ui:
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local Cash = Instance.new("IntValue", leaderstats)
Cash.Name = "Cash"
Cash.Value = 0
end)
Its not working. I don’t know why!
solys_ui
(Solys)
September 5, 2021, 12:47pm
#14
It does, you have to place it into an empty server script inside server script service
kry1068
(Flash)
September 5, 2021, 12:47pm
#15
It should be IntValue instead of NumberValue
ggb8y
(ggboi)
September 5, 2021, 12:51pm
#16
NumberValues do work, this script was working for me
Script:
game.Players.PlayerAdded:Connect(function(plr)
local ls = Instance.new("Folder", plr)
ls.Name = "leaderstats"
local Cash = Instance.new("NumberValue", ls)
Cash.Name = "Cash"
end)
Make sure it is in a script In ServerScriptService
You probably have a 3rd party script interferring or you leaderboards are disabled.
1 Like
PaintDevs
(Paint)
September 5, 2021, 12:54pm
#18
Here you go.
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder",player);
leaderstats.Name = "leaderstats";
local Cash = Instance.new("NumberValue",leaderstats);
Cash.Name = "Cash";
Cash.Value = 0;
end);
This works.
Should be a SERVERSCRIPT in SERVERSCRIPTSERVICE.
Oh there are other suggestions to similar scripts, didnt seen them whoops.
ggb8y
(ggboi)
September 5, 2021, 12:54pm
#19
If nothing works, try running this script:
local StarterGui = game:GetService("StarterGui")
StarterGui:SetCoreEnabled(Enum.CoreGuiType.PlayerList, true)
ggb8y
(ggboi)
September 5, 2021, 12:56pm
#20
For a second I thought you just copied my post. But its different