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

how i can remove all hats and create a new one on the player ?

Asked by 6 years ago
Edited 6 years ago

hello, or even hello again for some I'm still a beginner for the LUA script, I know a few tricks but I don't know how to do it, so I'm here to ask you for a little help.

local function ChangeClothes(char, shirtid, pantsid)
    local shirt = char:FindFirstChildOfClass"Shirt" or Instance.new("Shirt", char)
    local pants = char:FindFirstChildOfClass"Pants" or Instance.new("Pants", char)
    shirt.ShirtTemplate = shirtid
    pants.PantsTemplate = pantsid
end

local remote = game.ReplicatedStorage.TeamChange
    LVL2 = game.ReplicatedStorage["[SCP] Card-L2"]
        LVL4 = game.ReplicatedStorage["[SCP] Card-L4"]
        LVL3 = game.ReplicatedStorage["[SCP] Card-L3"]
        Flashlight = game.ReplicatedStorage.Flashlight


function remote.OnServerInvoke(player, TeamName)
    player.TeamColor = BrickColor.new(TeamName) -- Team Change
if player.TeamColor == BrickColor.new("New Yeller") then -- Searcher LVL 2

            player:LoadCharacter()
                   local char = player.Character or player.CharacterAdded:Wait()
        ChangeClothes(char, "rbxassetid://334887799", "rbxassetid://359977613") --replace with your desired ids         
        LVL2:Clone().Parent = game.Players[player.Name].Backpack
        Flashlight:Clone().Parent = game.Players[player.Name].Backpack

-- I WANT ADD THE SCRIPT PART HERE :D

I had already asked for the change of clothes but it was only just after I realized that I had to wear hats. lol

thanks you :)

1
You can use a loop to remove accessories and use InsertService to insert a hat from ROBLOX's catalog into the player's character. hellmatic 1523 — 6y
1
Get the player's hat by using :IsA("Hat") then :Destroy() and Instance.new("Accessory",Character) also Character.DescendantAdded:Connect() as well as :IsAncestorOf("Hat") HelperScripting -4 — 6y
0
how can i put it in my script ? (im a big noob with LUA ^^) sheppard929 9 — 6y

3 answers

Log in to vote
1
Answered by
hellmatic 1523 Moderation Voter
6 years ago
function REMOVE_HATS()
    for _, v in pairs(char:GetChildren()) do 
        if v:IsA('Accessory') then 
            v:Destroy()
        end
    end
end

local InsertService = game:GetService('InsertService')

function INSERT_HAT(hatid)
    local model = InsertService:LoadAssest(hatid)

    for _, v in pairs(model:GetChildren()) do 
        if v:IsA('Accessory') then 
            v.Parent = char
            model:Destroy() -- destroy model container
        end
    end
end
Ad
Log in to vote
0
Answered by 6 years ago

Do this: char.Humanoid:RemoveAccessories()

For the adding accessories, use char.Humanoid:AddAccessory()

I presume you would have to format it like this:

local NewAccessory = Instance.new("Accessory")
local Handle = Instance.new("Part") -- create the visible hat
Handle.Name = "Handle" -- REQUIRED
Handle.Parent = NewAccessory
local Mesh = Instance.new("Mesh") -- If you're not making a brick hat
-- Mesh.Texture = (whichever)
Mesh.Parent = Handle
local Attachment = Instance.new("Attachment")
Attachment.Parent = Handle -- and so forth
local Weld = Instance.new("ManualWeld")
Weld.Part0 = Handle
-- Weld.Part1 == blank
Weld.Parent = Handle
-- And so forth on
char.Humanoid:AddAccessory(NewAccessory)

If they don't work, then my apologies; I never actually have used this code before.

0
okay i will try sheppard929 9 — 6y
0
I don't know if it was me but I "pasted the script right after my game and ROBLOX STUDIO crashed" sheppard929 9 — 6y
0
I don't know how, every time my game crashes after I click "Stop." sheppard929 9 — 6y
0
You still have to add properties to the Mesh and the Weld and the Attachment and so forth. (Or add new handles.) sweetkid01 176 — 6y
0
the scripts not looks like work sheppard929 9 — 6y
Log in to vote
0
Answered by 6 years ago

I don't know what to do anymore, here is the whole script, basically what I want to do is that as soon as the player joins the team, all his hats are removed and a hat with the meshid "http://www.roblox.com/asset/?id=112643970" and the texture "http://www.roblox.com/asset/?id=112644004" I've never written this kind of thing yet (it's the beginning) sorry for bad english ^^ (french)

local function ChangeClothes(char, shirtid, pantsid)
    local shirt = char:FindFirstChildOfClass"Shirt" or Instance.new("Shirt", char)
    local pants = char:FindFirstChildOfClass"Pants" or Instance.new("Pants", char)
    shirt.ShirtTemplate = shirtid
    pants.PantsTemplate = pantsid
end

local remote = game.ReplicatedStorage.TeamChange
    LVL2 = game.ReplicatedStorage["[SCP] Card-L2"]
        LVL4 = game.ReplicatedStorage["[SCP] Card-L4"]
        LVL3 = game.ReplicatedStorage["[SCP] Card-L3"]
        Flashlight = game.ReplicatedStorage.Flashlight


function remote.OnServerInvoke(player, TeamName)
    player.TeamColor = BrickColor.new(TeamName) -- Team Change
if player.TeamColor == BrickColor.new("New Yeller") then -- Searcher LVL 2

            player:LoadCharacter()
                   local char = player.Character or player.CharacterAdded:Wait()
        ChangeClothes(char, "rbxassetid://334887799", "rbxassetid://359977613") --replace with your desired ids         
        LVL2:Clone().Parent = game.Players[player.Name].Backpack
        Flashlight:Clone().Parent = game.Players[player.Name].Backpack
elseif player.TeamColor == BrickColor.new("Deep orange") then -- Searcher LVL 4

                player:LoadCharacter()
                 local char = player.Character or player.CharacterAdded:Wait()
        ChangeClothes(char, "rbxassetid://519722780", "rbxassetid://519722963")
        LVL4:Clone().Parent = game.Players[player.Name].Backpack
        Flashlight:Clone().Parent = game.Players[player.Name].Backpack -- Class D

elseif player.TeamColor == BrickColor.new("Gold") then
                player:LoadCharacter()
                 local char = player.Character or player.CharacterAdded:Wait()
        ChangeClothes(char, "rbxassetid://303911572", "rbxassetid://303911192")
elseif player.TeamColor == BrickColor.new("Cyan") then -- SCP Guard

                player:LoadCharacter()
                         local char = player.Character or player.CharacterAdded:Wait()
        ChangeClothes(char, "rbxassetid://519722780", "rbxassetid://519722963")
        LVL3:Clone().Parent = game.Players[player.Name].Backpack
end
end




Answer this question