I need help making a leaderstats based tag system

Hi Guys! This is my first post here, as I just got promoted to member. I have been dying to ask this question. So I want to make a ServerScriptService script where it makes tags for the player if they are above or below a certain number of the leaderstats. Here is the code I already have

game.Players.PlayerAdded:connect(function(plr)
	local tags = Instance.new("Folder",plr)
	tags.Name = "Tags";
	if false == true then
	elseif plr.Name == "NightHowlersYT" then -- Player Name
		
		local newTag = Instance.new("IntValue",tags);local chatColor = Instance.new("Color3Value",newTag);local tagColor = Instance.new("Color3Value",newTag);chatColor.Name = "ChatColor";tagColor.Name = "TagColor"

		--EDIT BELOW
        newTag.Name = "DriftBoss" -- Tag Name
        chatColor.Value = Color3.fromRGB(159, 243, 233) -- Chat Color (default is 255,255,255)
        tagColor.Value = Color3.fromRGB(159, 243, 233) -- Tag Color

		elseif plr.Name == "ThatDiamondMustache" then -- Player Name
		
		local newTag = Instance.new("IntValue",tags);local chatColor = Instance.new("Color3Value",newTag);local tagColor = Instance.new("Color3Value",newTag);chatColor.Name = "ChatColor";tagColor.Name = "TagColor"

		--EDIT BELOW
        newTag.Name = "Administrator" -- Tag Name
        chatColor.Value = Color3.fromRGB(159, 243, 233) -- Chat Color (default is 255,255,255)
        tagColor.Value = Color3.fromRGB(159, 243, 233) -- Tag Color

	elseif plr.Name == "graydog97" then -- Player Name
		
		local newTag = Instance.new("IntValue",tags);local chatColor = Instance.new("Color3Value",newTag);local tagColor = Instance.new("Color3Value",newTag);chatColor.Name = "ChatColor";tagColor.Name = "TagColor"

		--EDIT BELOW
        newTag.Name = "yes" -- Tag Name
        chatColor.Value = Color3.fromRGB(159, 243, 233) -- Chat Color (default is 255,255,255)
        tagColor.Value = Color3.fromRGB(159, 243, 233) -- Tag Color

	elseif plr.Name == "ServverMessage" then -- Player Name
		
		local newTag = Instance.new("IntValue",tags);local chatColor = Instance.new("Color3Value",newTag);local tagColor = Instance.new("Color3Value",newTag);chatColor.Name = "ChatColor";tagColor.Name = "TagColor"

		--EDIT BELOW
        newTag.Name = "s h i r t" -- Tag Name
        chatColor.Value = Color3.fromRGB(159, 243, 233) -- Chat Color (default is 255,255,255)
        tagColor.Value = Color3.fromRGB(159, 243, 233) -- Tag Color

	elseif plr.Name == "AmirLyra" then -- Player Name
		
		local newTag = Instance.new("IntValue",tags);local chatColor = Instance.new("Color3Value",newTag);local tagColor = Instance.new("Color3Value",newTag);chatColor.Name = "ChatColor";tagColor.Name = "TagColor"

		--EDIT BELOW
        newTag.Name = "MR. NUKE" -- Tag Name
        chatColor.Value = Color3.fromRGB(159, 243, 233) -- Chat Color (default is 255,255,255)
        tagColor.Value = Color3.fromRGB(159, 243, 233) -- Tag Color

	elseif plr.Name == "PitSteel07" then -- Player Name
		
		local newTag = Instance.new("IntValue",tags);local chatColor = Instance.new("Color3Value",newTag);local tagColor = Instance.new("Color3Value",newTag);chatColor.Name = "ChatColor";tagColor.Name = "TagColor"

		--EDIT BELOW
        newTag.Name = "Drift Legend" -- Tag Name
        chatColor.Value = Color3.fromRGB(159, 243, 233) -- Chat Color (default is 255,255,255)
        tagColor.Value = Color3.fromRGB(159, 243, 233) -- Tag Color

	elseif plr.Name == "NIFFER99" then -- Player Name
		
		local newTag = Instance.new("IntValue",tags);local chatColor = Instance.new("Color3Value",newTag);local tagColor = Instance.new("Color3Value",newTag);chatColor.Name = "ChatColor";tagColor.Name = "TagColor"

		--EDIT BELOW
        newTag.Name = "Most Wanted" -- Tag Name
        chatColor.Value = Color3.fromRGB(159, 243, 233) -- Chat Color (default is 255,255,255)
        tagColor.Value = Color3.fromRGB(159, 243, 233) -- Tag Color

	elseif plr.Name ~= "PitSteel07" or "AmirLyra" or "Servver Message" or "graydog97" or "ThadDiamondMustache" or "NightHowlersYT" or "NIFFER99" or "Trashnoob362" then -- Player Name
		
		local newTag = Instance.new("IntValue",tags);local chatColor = Instance.new("Color3Value",newTag);local tagColor = Instance.new("Color3Value",newTag);chatColor.Name = "ChatColor";tagColor.Name = "TagColor"

		--EDIT BELOW
        newTag.Name = "Ameteur Drifter" -- Tag Name
        tagColor.Value = Color3.fromRGB(255,255,255) -- Tag Color
	    chatColor.Value = Color3.fromRGB(255,255,255) -- Chat Color (default is 255,255,255)

	elseif plr.Name == "Trashnoob362" then -- Player Name
		
		local newTag = Instance.new("IntValue",tags);local chatColor = Instance.new("Color3Value",newTag);local tagColor = Instance.new("Color3Value",newTag);chatColor.Name = "ChatColor";tagColor.Name = "TagColor"

		--EDIT BELOW
        newTag.Name = "big brain driver" -- Tag Name
        chatColor.Value = Color3.fromRGB(159, 243, 233) -- Chat Color (default is 255,255,255)
        tagColor.Value = Color3.fromRGB(159, 243, 233) -- Tag Color

	end
end)

I tried something like: if player.leaderstats.MilesDriven.Value > 19.9 then

tag code
but that didn’t work. I have not seen a solution anywhere, checking the devforums, YouTube, the Toolbox, etc. Thank you in advance!

2 Likes

Your

if player.leaderstats.MilesDriven.Value > 19.9 then

should work! Your problem must have been in the way you implemented it. If you had put it directly underneath the PlayerAdded function then it would have only checked how far they have driven as soon as they joined the game! You’d want it to check every time their miles updated!

You can do that by creating a new function inside your PlayerAdded function!

local PreviousMilestone = 0
local newTag = Instance.new("IntValue",tags);local chatColor = Instance.new("Color3Value",newTag);local tagColor = Instance.new("Color3Value",newTag);chatColor.Name = "ChatColor";tagColor.Name = "TagColor"

player.leaderstats.MilesDriven:GetPropertyChangedSignal("Value"):Connect(function() 
    local Miles = player.leaderstats.MilesDriven.Value 
    if Miles >= 20 and Miles <= 100 and PreviousMilestone < 1 then 
        PreviousMilestone = 1
        newTag.Name = "20 MILES!!!" -- Tag Name
        chatColor.Value = Color3.fromRGB(159, 243, 233) -- Chat Color (default is 255,255,255)
        tagColor.Value = Color3.fromRGB(159, 243, 233) -- Tag Color
    elseif Miles > 100 and Miles < 500 and PreviousMilestone < 2 then
        PreviousMilestone = 2 
        newTag.Name = "100 MILES!!!" -- Tag Name
        chatColor.Value = Color3.fromRGB(159, 100, 233) -- Chat Color (default is 255,255,255)
        tagColor.Value = Color3.fromRGB(159, 100, 233) -- Tag Color
    end
end)

When creating new tags make sure PreviousMilestone is set to 1 greater then the one before it.

I hope this helps, if something went wrong let us know!

1 Like

THANK YOU SO MUCH!!! I am going to test this out. If it works, I will click the button to make it the solution. I cannot thank you enough!

edit: Wait, so I can directly put this under the function without keeping the previous tags script?

I DO get an error, this is what I did to the code. (I am a complete noob at Lua scripting) But it doesnt work.

game.Players.PlayerAdded:connect(function(plr)
	local tags = Instance.new("Folder",plr)
	tags.Name = "Tags";
	if false == true then
local PreviousMilestone = 0
local newTag = Instance.new("IntValue",tags);local chatColor = Instance.new("Color3Value",newTag);local tagColor = Instance.new("Color3Value",newTag);chatColor.Name = "ChatColor";tagColor.Name = "TagColor"
player.leaderstats.MilesDriven:GetPropertyChangedSignal("Value"):Connect(function() 
    local Miles = player.leaderstats.MilesDriven.Value 
    if Miles >= 20 and Miles <= 100 and PreviousMilestone < 1 then 
        PreviousMilestone = 1
        newTag.Name = "20 MILES!!!" -- Tag Name
        chatColor.Value = Color3.fromRGB(159, 243, 233) -- Chat Color (default is 255,255,255)
        tagColor.Value = Color3.fromRGB(159, 243, 233) -- Tag Color
    elseif Miles > 100 and Miles < 500 and PreviousMilestone < 2 then
        PreviousMilestone = 2 
        newTag.Name = "100 MILES!!!" -- Tag Name
        chatColor.Value = Color3.fromRGB(159, 100, 233) -- Chat Color (default is 255,255,255)
        tagColor.Value = Color3.fromRGB(159, 100, 233) -- Tag Color
    end
end)

I don’t know if I need to remove or add an end or end)

Delete this statement:

if false == true then 

There is probably an end connected to this aswell that you’ll need to find and delete.

1 Like

I also get an error for the player. Unknown global player. or something like that.

For everything that says player replace with “plr”.

1 Like

Hmm. That seemed to fix that error, now i get Expected to end function at line 1, instead got left arrow eof right arrow

add a end) at the end of the code

1 Like

Thanks
(30 charactersssssssssssssssssssssss)

ok so i dont have miles driven in Studio because i dont have API on, so when the person doesnt have miles driven it shows: Value as the tag
EDIT: Code

game.Players.PlayerAdded:connect(function(plr)
	local tags = Instance.new("Folder",plr)
	tags.Name = "Tags";
local PreviousMilestone = 0
local newTag = Instance.new("IntValue",tags);local chatColor = Instance.new("Color3Value",newTag);local tagColor = Instance.new("Color3Value",newTag);chatColor.Name = "ChatColor";tagColor.Name = "TagColor"

plr.leaderstats.MilesDriven:GetPropertyChangedSignal("Value"):Connect(function() 
    local Miles = plr.leaderstats.MilesDriven.Value 
    if Miles >= 20 and Miles <= 100 and PreviousMilestone < 1 then 
        PreviousMilestone = 1
        newTag.Name = "20 MILES!!!" -- Tag Name
        chatColor.Value = Color3.fromRGB(159, 243, 233) -- Chat Color (default is 255,255,255)
        tagColor.Value = Color3.fromRGB(159, 243, 233) -- Tag Color
    elseif Miles > 100 and Miles < 500 and PreviousMilestone < 2 then
        PreviousMilestone = 2 
        newTag.Name = "100 MILES!!!" -- Tag Name
        chatColor.Value = Color3.fromRGB(159, 100, 233) -- Chat Color (default is 255,255,255)
        tagColor.Value = Color3.fromRGB(159, 100, 233) -- Tag Color
    end
end)
end)

You can put

newTag.Name = "0 MILES" -- Tag Name

Right after

local newTag = Instance.new("IntValue",tags);local chatColor = Instance.new("Color3Value",newTag);local tagColor = Instance.new("Color3Value",newTag);chatColor.Name = "ChatColor";tagColor.Name = "TagColor"

and it’ll do the trick.

1 Like

Thanks. I will see if it works.

IT WORKS! Thank you so much! I really appreciate the immediate help!

1 Like

Hmmmm. I am stuck at Ameteur at 51.something miles…

game.Players.PlayerAdded:connect(function(plr)
	local tags = Instance.new("Folder",plr)
	tags.Name = "Tags";
local PreviousMilestone = 0
local newTag = Instance.new("IntValue",tags);local chatColor = Instance.new("Color3Value",newTag);local tagColor = Instance.new("Color3Value",newTag);chatColor.Name = "ChatColor";tagColor.Name = "TagColor"
newTag.Name = "Noob" -- Tag Nam
plr.leaderstats.MilesDriven:GetPropertyChangedSignal("Value"):Connect(function() 
    local Miles = plr.leaderstats.MilesDriven.Value 
    if Miles >= 20 and Miles <= 100 and PreviousMilestone < 1 then 
        PreviousMilestone = 1
        newTag.Name = "Ameteur" -- Tag Name
        chatColor.Value = Color3.fromRGB(159, 243, 233) -- Chat Color (default is 255,255,255)
        tagColor.Value = Color3.fromRGB(159, 243, 233) -- Tag Color
    elseif Miles > 50 and Miles < 500 and PreviousMilestone < 2 then
        PreviousMilestone = 2 
        newTag.Name = "Semi-Pro" -- Tag Name
        chatColor.Value = Color3.fromRGB(159, 100, 233) -- Chat Color (default is 255,255,255)
        tagColor.Value = Color3.fromRGB(159, 100, 233) -- Tag Color
    elseif Miles > 100 and Miles < 500 and PreviousMilestone < 3 then
        PreviousMilestone = 3 
        newTag.Name = "Pro" -- Tag Name
        chatColor.Value = Color3.fromRGB(159, 100, 233) -- Chat Color (default is 255,255,255)
        tagColor.Value = Color3.fromRGB(159, 100, 233) -- Tag Color
    elseif Miles > 200 and Miles < 500 and PreviousMilestone < 4 then
        PreviousMilestone = 4 
        newTag.Name = "Elite" -- Tag Name
        chatColor.Value = Color3.fromRGB(159, 100, 233) -- Chat Color (default is 255,255,255)
        tagColor.Value = Color3.fromRGB(159, 100, 233) -- Tag Color
    elseif Miles > 300 and Miles < 500 and PreviousMilestone < 5 then
        PreviousMilestone = 5 
        newTag.Name = "Legendary" -- Tag Name
        chatColor.Value = Color3.fromRGB(159, 100, 233) -- Chat Color (default is 255,255,255)
        tagColor.Value = Color3.fromRGB(159, 100, 233) -- Tag Color
    end
end)
end)

EDIT1:I AM AN IDIOT… I can fix it… lol.

EDIT2: Fixed it!

1 Like