What do you want to achieve?
I want to make a script that create a leaderstat with a custom name and that when the player join the leaderstat value is custom too. Of course it could be changed per others scripts. Also I don’t want the leaderstat to save.
What is the issue?
I read all the leaderstat’s page of the creator documention, but I don’t understand how the script that I want would look.
What solutions have you tried so far?
I found some things about leaderstats but it’s not what I want.
This script will help me for a lot of situations, and every help you give will make me a better developer than before! Thanks!
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(plr)
local Leaderstats = Instance.new("Folder") -- create the leaderstats folder
Leaderstats.Name = "leaderstats" -- MUST be lowercase
local Cash = Instance.new("IntValue")
Cash.Name = "Cash" -- change name here
Cash.Value = math.random(0,100) -- random value between 0 and 100
Cash.Parent = Leaderstats -- make sure the value is in the folder
Leaderstats.Parent = plr -- parent it to the player so it can be visible
end)
I don’t know what you are trying to achieve but this should help you out.
just that line I think it’s noy what I want because I don’t want to the leaderstat to have a random value of 1 to 100, I want it to have a value that I choose.
If I replace math.random(0,100) per "LeaderstatValueHere", will it works?
Float (Or Floating Point Number) is a Number with Decimals
Examples: 3.14159, 1.01, 4.5
So in the Use case between an IntValue and a NumberValue, Just remember that an IntValue only Stores Whole Numbers while a NumberValue can store Decimals.
No, because assigning a string to a value other than an StringValue will error. You will have to change the Instance that you are creating. This is the place where you change it:
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(plr)
local Leaderstats = Instance.new("Folder") -- create the leaderstats folder
Leaderstats.Name = "leaderstats" -- MUST be lowercase
local Cash = Instance.new("StringValue")
Cash.Name = "Cash" -- change name here
Cash.Value = "CashValue" -- a string
Cash.Parent = Leaderstats -- make sure the value is in the folder
Leaderstats.Parent = plr -- parent it to the player so it can be visible
end)
I’ve modified a bit the code of @SomeFedoraGuy to fit with your case :
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(plr)
local Leaderstats = Instance.new("Folder") -- create the leaderstats folder
Leaderstats.Name = "leaderstats" -- MUST be lowercase
local Value = Instance.new("IntValue")
Value.Name = "LeaderstatsValueHere" -- change name here
Value.Value = 0 -- your value
Value.Parent = Leaderstats -- make sure the value is in the folder
Leaderstats.Parent = plr -- parent it to the player so it can be visible
end)
Hello! I’ve modified a bit of your code to fit fit with your issue.
Here is the code.
game.Players.PlayerAdded:Connect(function(plr)
-- leaderstats
local leaderstats = Instance.new("Folder") -- creates the folder
leaderstats.Parent = plr -- places it as a child of the player
leaderstats.Name = "leaderstats" -- names the folder
--Deaths
local deaths = Instance.new("IntValue") -- creates the integer value
deaths.Parent = leaderstats -- places it as a child of leaderstats
deaths.Name = "Deaths" -- names the value
if plr.Character then -- if the player has a character
plr.Character.Humanoid.Died:Connect(function() -- if the character died
deaths.Value = deaths.Value+1 -- adds 1 more death to the value
end
end
--Group1
local group1 = Instance.new("IntValue") -- creates the value for group1
group1.Name = "Group1" -- CHANGE "Group1" TO YOUR GROUP NAME
group1.Parent = leaderstats
group1.Value = plr:GetRoleInGroup(Group1) -- CHANGE "Group1" TO YOUR GROUP ID
--Group2
local group2 = Instance.new("IntValue") -- creates the value for group1
group2.Name = "Group2" -- CHANGE "Group2" TO YOUR GROUP NAME
group2.Parent = leaderstats
group2.Value = plr:GetRoleInGroup(Group2) -- CHANGE "Group2" TO YOUR GROUP ID
end)
I added kills and deaths, but you can rename it to whatever you want.
If you found my answer helpful, be sure to mark it as the solution!