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

This wont Work, Help?!

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
script.Parent.DialogChoiceSelected:connect(function(choice, player)
        if player.GetRankInGroup (2672272) >= 2 then
            game.ServerStorage:findFirstChild(choice.Name)
            game.ServerStorage:findFirstChild(choice.Name):clone().Parent = workspace
        end
    end)

18:35:22.454 - GetRankInGroup is not a valid member of DialogChoice

1 answer

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

There are a few minor errors here:

script.Parent.DialogChoiceSelected:connect(function(player, choice)
    if player:GetRankInGroup(2672272) >= 2 then
        if game.ServerStorage:FindFirstChild(choice.Name) then
            game.ServerStorage[choice.Name]:Clone().Parent = workspace
        end
    end
end)

In the first line, you simply had the parameters backwards.

In the second line, GetRankInGroup is called as a method, not a function. This is true for I think every ROBLOX-provided function.

The third line uses the older (now technically deprecated) findFirstChild. In future code, use FindFirstChild instead. Same with clone vs. Clone.

Also in the third line, you aren't actually checking that it exists. If the FindFirstChild fails to find anything, it'll try to Clone that nothing anyway, producing an error. Needs an if statement.

And, finally, on the fourth line, you don't need to repeat the FindFirstChild, since it's known to already exist. Simply use brackets to directly access it.

Ad

Answer this question