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 7 years ago
Edited 7 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.

01local function ChangeClothes(char, shirtid, pantsid)
02    local shirt = char:FindFirstChildOfClass"Shirt" or Instance.new("Shirt", char)
03    local pants = char:FindFirstChildOfClass"Pants" or Instance.new("Pants", char)
04    shirt.ShirtTemplate = shirtid
05    pants.PantsTemplate = pantsid
06end
07 
08local remote = game.ReplicatedStorage.TeamChange
09    LVL2 = game.ReplicatedStorage["[SCP] Card-L2"]
10        LVL4 = game.ReplicatedStorage["[SCP] Card-L4"]
11        LVL3 = game.ReplicatedStorage["[SCP] Card-L3"]
12        Flashlight = game.ReplicatedStorage.Flashlight
13 
14 
15function remote.OnServerInvoke(player, TeamName)
View all 25 lines...

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 — 7y
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 — 7y
0
how can i put it in my script ? (im a big noob with LUA ^^) sheppard929 9 — 7y

3 answers

Log in to vote
1
Answered by
hellmatic 1523 Moderation Voter
7 years ago
01function REMOVE_HATS()
02    for _, v in pairs(char:GetChildren()) do
03        if v:IsA('Accessory') then
04            v:Destroy()
05        end
06    end
07end
08 
09local InsertService = game:GetService('InsertService')
10 
11function INSERT_HAT(hatid)
12    local model = InsertService:LoadAssest(hatid)
13 
14    for _, v in pairs(model:GetChildren()) do
15        if v:IsA('Accessory') then
16            v.Parent = char
17            model:Destroy() -- destroy model container
18        end
19    end
20end
Ad
Log in to vote
0
Answered by 7 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:

01local NewAccessory = Instance.new("Accessory")
02local Handle = Instance.new("Part") -- create the visible hat
03Handle.Name = "Handle" -- REQUIRED
04Handle.Parent = NewAccessory
05local Mesh = Instance.new("Mesh") -- If you're not making a brick hat
06-- Mesh.Texture = (whichever)
07Mesh.Parent = Handle
08local Attachment = Instance.new("Attachment")
09Attachment.Parent = Handle -- and so forth
10local Weld = Instance.new("ManualWeld")
11Weld.Part0 = Handle
12-- Weld.Part1 == blank
13Weld.Parent = Handle
14-- And so forth on
15char.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 — 7y
0
I don't know if it was me but I "pasted the script right after my game and ROBLOX STUDIO crashed" sheppard929 9 — 7y
0
I don't know how, every time my game crashes after I click "Stop." sheppard929 9 — 7y
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 — 7y
0
the scripts not looks like work sheppard929 9 — 7y
Log in to vote
0
Answered by 7 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)

01local function ChangeClothes(char, shirtid, pantsid)
02    local shirt = char:FindFirstChildOfClass"Shirt" or Instance.new("Shirt", char)
03    local pants = char:FindFirstChildOfClass"Pants" or Instance.new("Pants", char)
04    shirt.ShirtTemplate = shirtid
05    pants.PantsTemplate = pantsid
06end
07 
08local remote = game.ReplicatedStorage.TeamChange
09    LVL2 = game.ReplicatedStorage["[SCP] Card-L2"]
10        LVL4 = game.ReplicatedStorage["[SCP] Card-L4"]
11        LVL3 = game.ReplicatedStorage["[SCP] Card-L3"]
12        Flashlight = game.ReplicatedStorage.Flashlight
13 
14 
15function remote.OnServerInvoke(player, TeamName)
View all 43 lines...

Answer this question