Roblox OnClick 衣服赠送脚本

 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

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)

该脚本会在你点击按钮后为你赠送指定的衣服(脚本位于按钮下方,有一个点击检测器),但仅当你在某个团队中拥有特定的等级时才会赠送衣服。但目前它不能正常工作,该如何修复?

点赞
用户1938640
用户1938640

避免使用类似于 pnts 这样奇奇怪怪的名称,添加字母 a 也不会导致你死亡。

ClickDetector已经提供了玩家

总的来说非常混乱

试试这个:

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

local GroupID = 42 -- 在这里填写组ID

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

    -- 获取新的上衣
    local CharacterShirt = Character:findFirstChild("Shirt")
    if CharacterShirt then CharacterShirt:Destroy() end
    Shirt:Clone().Parent = Character

    -- 获取新的裤子
    local CharacterPants = Character:findFirstChild("Pants")
    if CharacterPants then CharacterPants:Destroy() end
    Pants:Clone().Parent = Character
end)

还要确保在寻求帮助时要提交错误

2016-08-20 11:15:42