Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to fix this script?

Asked by
IXLKIDDO 110
9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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?

3 answers

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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)
0
Thank you so much, this is the most helpful answer that I have received. About closing the " (sorry, new to this site so I don't know how to make it like a code), I realized this shortly after making this post. Also, your line 2 doesn't appear to be needed as it seems that the script works (probably due to the parent script that is partnered with it). However, I'll keep this in mind if I make it IXLKIDDO 110 — 9y
Ad
Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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.

Log in to vote
-2
Answered by
pauljkl 10
9 years ago

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.

Answer this question