What I've tried to do is create a leaderboard stat that shows both the group that the person is home to and that person's rank in them. However, when trying to use this, the stat itself does not show (even with a blank value.
game.Players.PlayerAdded:connect(function(newPlayer) repeat wait() until newPlayer:findFirstChild("leaderstats") local Rank = Instance.new("StringValue", newPlayer.leaderstats) Rank.Name = "Rank" if newPlayer:IsInGroup(2553045) then Rank.Value = "MRR [Host]:" + newPlayer:GetRoleInGroup(2553045) elseif newPlayer:IsInGroup(316950) then Rank.Value = "Fatal Redemption [Ally]" + newPlayer:GetRoleInGroup(316950) elseif newPlayer:IsInGroup (914233) then Rank.Value = "Allied Airborne [Enemy] + newPlayer:GetRoleInGroup(914233) elseif newPlayer:IsInGroup() then Rank.Value = "Visitor/Floater" end end)
I'm a bit new to roblox coding so just tell me if my assumptions are correct with the fact that you can't use the + to add in more text. Does anyone know how to fix this?
The concatenation operator in Lua is ..
, so you're correct there. The problem, as I see it, is you're assuming that leaderstats
is created for you, which it isn't. You're also missing a "
on line 10.
game.Players.PlayerAdded:connect(function(newPlayer) Instance.new("IntValue", newPlayer).Name = "leaderstats" local Rank = Instance.new("StringValue", newPlayer.leaderstats) Rank.Name = "Rank" if newPlayer:IsInGroup(2553045) then Rank.Value = "MRR [Host]: " .. newPlayer:GetRoleInGroup(2553045) elseif newPlayer:IsInGroup(316950) then Rank.Value = "Fatal Redemption [Ally]: " .. newPlayer:GetRoleInGroup(316950) elseif newPlayer:IsInGroup(914233) then Rank.Value = "Allied Airborne [Enemy]: " .. newPlayer:GetRoleInGroup(914233) else --No need for an `if` here. if/elseif chains are the 'switch' statements of Lua. `else` is the default case. Rank.Value = "Visitor/Floater" end end)
You can't use +
to concatenate text in Lua. This is because 5 + "3"
evaluates to 8
-- it also makes sure you meant that, as opposed to wanting 53
.
You use the concatenation operator ..
to join text.
You also have a syntax error on line 10; you didn't finish the string with a closing "
.
It's probably a good idea to make variables for the different group ids since you repeat them.
The script is probably getting stuck before the creation, put a print statement before and after the repeat loop to make sure as I cannot see any point at which you create the "leaderstats" object.