i’m trying to call upon the players stats so that it’ll then change the rank stat
Which line is erroring? And can you provide that line here?
this is a localscript right?
you can’t get localplayer in a server script so player would be nil
just noticed it’s in serverscriptservice too
local Player = game.Players.LocalPlayer
local LeaderStats = Player:WaitForChild("leaderstats")
local Rank = LeaderStats:WaitForChild("Rank")
local Group = LeaderStats:WaitForChild("Group")
local Contribution = LeaderStats:WaitForChild("Contribution")
local DemonSlayer = LeaderStats:WaitForChild("DemonSlayer")
if DemonSlayer.Value == true then
Rank.Value = "Mizunoto"
end
local function RankCheck()
if Contribution.Value >= 100 then
Rank.Value = "Mizunoe"
elseif Contribution.Value >= 300 then
Rank.Value = "Kanoto"
elseif Contribution.Value >= 500 then
Rank.Value = "Kanoe"
elseif Contribution.Value >= 600 then
Rank.Value = "Tsuchinoto"
elseif Contribution.Value >= 700 then
Rank.Value = "Tasuchinoe"
else
Rank.Value = "Mizunoto"
end
end
RankCheck()
In this fixed code, I’ve changed “LeaderStats” on line 3 and “Leaderstats” on line 5 to match the correct capitalization. Also, I’ve corrected the conditional on line 7 to check the value of “DemonSlayer” using “DemonSlayer.Value” instead of just “DemonSlayer”.
There is the corrected code, I hope it helps you.
You cannot use LocalPlayer in a server script. You can use the game.Players.PlayerAdded
event
Example:
game.Players.PlayerAdded:Connect(function(Player)
local LeaderStats = Player:WaitForChild("leaderstats")
--...
end)
i’m pretty sure you could also shorten your RankCheck function by using a ‘Ranks’ dictionary and a for loop
it’ll also be easier able to add ranks
local Ranks = {
["Mizunoto"] = 100,
["Tasuchinoe"] = 300,
["Kanoe"] = 500,
["Kanoto"] = 600,
["Mizunoe"] = 700
}
local function RankCheck()
for Title, MaxXP in Ranks do -- assuming the numbers are XP values (MaxXP)
if Contribution.Value >= MaxXP then
Rank.Value = Title
end
end
end
RankCheck()
correct me if i’m wrong
its line number 2
I’ll try that since i never knew you could do that
do i put the all the variables like Rank and groups into the function?
Anyways, if it’s showing actual leaderstats in game, it should be spelled “leaderstats” (all lowercase).
Why are you spelling it like this: “LeaderStats”? If it’s actually showing up in game, that means you spelled correctly the first time so try replacing “LeaderStats” with “leaderstats”.
i named it that cause in my datastore its also named like this
You should be doing this RankCheck
function in a server script. Additionally, RankCheck
won’t work anyways because it is out of scope.
Where should i do the rank check?
On the server in your leaderstats script.