Roblox OnClick clothers给予脚本

时间:2016-08-13 20:44:06

标签: lua roblox

 pnts = script.Pants
shirt = script.Shirt

function onClicked(playerWhoClicked)

end
function GiveClothes(character)
if not character:findFirstChild("Shirt") then 
shirt:Clone().Parent = character
else character:findFirstChild("Shirt"):Destroy()
shirt:Clone().Parent = character
end

if not character:findFirstChild("Pants") then 
pnts:Clone().Parent = character
else character:findFirstChild("Pants"):Destroy()
pnts:Clone().Parent = character
end
end

game.Players.PlayerAdded:connect(function(p)
p.CharacterAdded:connect(function(char)
wait(1.12)
local plr = game.Players:findFirstChild(char.Name)
print(char.Name)

local groupid = 0 -- Id of your group

local plr =  game.Players:GetPlayerFromCharacter(part.Parent)

if plr then

if plr:IsInGroup(groupid) then

if plr:GetRoleInGroup(groupId) >= 50 
then GiveClothes(char)
end
end 
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

如果你点击按钮(脚本在按钮下面,是的,还有一个ClickDetector),这个脚本应该给你一些衣服,但如果你是一个组中的某个等级,它只给你衣服。

但目前它不起作用。如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

避免像pnts这样奇怪的名字,你可能不会因添加字母a

而死

The ClickDetector already give you the player

这一切都凌乱不堪

试试这个:

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

local GroupID = 42 -- 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)

请务必在寻求帮助时发布errors