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

Why won't this onclick clothes giver work?

Asked by 4 years ago
local Pants = script.Pants
local Shirt = script.Shirt

local GroupID = 6763603 -- Group id here

script.Parent.ClickDetector.MouseClick:connect(function(Player)
    if not Player:IsInGroup(GroupID) then return end
    if Player:GetRoleInGroup(GroupID) < 50 then return end
    local Character = Player.Character
    if Character == nil then return end

    -- Get new shirt
    local CharacterShirt = Character:findFirstChild("Shirt")
    if CharacterShirt then CharacterShirt:Destroy() end
    Shirt:Clone().Parent = Character

    -- Get new pants
    local CharacterPants = Character:findFirstChild("Pants")
    if CharacterPants then CharacterPants:Destroy() end
    Pants:Clone().Parent = Character
end)

In the output it say's "Workspace.Part.Script:8: attempt to compare string and number"

1 answer

Log in to vote
0
Answered by 4 years ago

The reason why your script won't work is actually very simple, by doing Player:GetRoleInGroup it would print out the name of the role they have in the group, if you wanted to get the number corresponding to their role, you would do :GetRankInGroup. If you take this into account, the script would look like this.

local Pants = script.Pants
local Shirt = script.Shirt

local GroupID = 6763603 -- Group id here

script.Parent.ClickDetector.MouseClick:connect(function(Player)
    if not Player:IsInGroup(GroupID) then return end
    if Player:GetRankInGroup(GroupID) < 50 then return end
    local Character = Player.Character
    if Character == nil then return end

    -- Get new shirt
    local CharacterShirt = Character:findFirstChild("Shirt")
    if CharacterShirt then CharacterShirt:Destroy() end
    Shirt:Clone().Parent = Character

    -- Get new pants
    local CharacterPants = Character:findFirstChild("Pants")
    if CharacterPants then CharacterPants:Destroy() end
    Pants:Clone().Parent = Character
end)
0
Thank's alot this solved my problem, but any clue how to add more than role id? Asherharding10 12 — 4y
0
If you could help that would be nice :) Asherharding10 12 — 4y
Ad

Answer this question