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

Simple error? Or... qq

Asked by 9 years ago
function joined(plr)
local a = Instance.new("Hint", game.Workspace)
a.Text = plr.Name.. "has joined! | Age: " ..plr.AccountAge.. " | " ..plr.MembershipType
wait(10)
a:remove()
end
game.Players.PlayerAdded:connect(joined)

1
You haven't said what the error in the output is, or what line the script breaks on. General_Scripter 425 — 9y
0
"Workspace.Script:3: attempt to concatenate field 'MembershipeType' (a userdata value)" Ethan_Waike 156 — 9y

1 answer

Log in to vote
3
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
9 years ago

The problem is that MembershipType is an Enum. An Enum is a userdata value and cannot be concatenated.

There are two ways to do this. The easier way is to simply convert the enum to a string and chop off the Enum.MembershipType. part of it. This way it will return None, BuildersClub, TurboBuildersClub, or OutrageousBuildersClub.

function joined(plr)
    local a = Instance.new("Hint", game.Workspace)
    local membership = string.sub(tostring(game.Players.Player.MembershipType), 21)

    a.Text = plr.Name.. "has joined! | Age: " ..plr.AccountAge.. " | " .. membership
    wait(10)
    a:remove()
end

game.Players.PlayerAdded:connect(joined)

The other way to do this is to check which enum is being used and change the message accordingly. This allows you to use abreviations or what ever you'd like.

function joined(plr)
    local a = Instance.new("Hint", game.Workspace)
    local membership

    if plr.MembershipType == Enum.MembershipType.None then
        membership= "NBC"
    elseif plr.MembershipType == Enum.MembershipType.BuildersClub then
        membership= "BC"
    elseif plr.MembershipType == Enum.MembershipType.TurboBuildersClub then
        membership= "TBC"
    elseif plr.MembershipType == Enum.MembershipType.OutrageousBuildersClub then
        membership= "OBC"
    end

    a.Text = plr.Name.. "has joined! | Age: " ..plr.AccountAge.. " | " .. membership
    wait(10)
    a:remove()
end

game.Players.PlayerAdded:connect(joined)
0
Thanks sooo much Ethan_Waike 156 — 9y
0
No problem :) BlackJPI 2658 — 9y
Ad

Answer this question