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

How would I put a hat onto a Player? Character Customization

Asked by 9 years ago

I have 2 different copies of hats inside of game.ReplicatedStroage.Hats.M > Hat1 and Hat2 are inside it, I would like the script to put a hat on, but using a Value of script.Parent.Hat

So player touches the brick and then he gets the Shirt, Pants, Face, but also a Hat, the same way Shirt and Pants are put on...

I'm trying to achieve a Character Customization system which could be easily edited, that's why I need it all in StringValues. I'm planning to add buttons which would change the Shirt/Pants/Face/Hat of the humanoid, and then when a Player steps on it, they will get the same look. - I would be extremely thankful if anyone of you has a model of this and could share it with me, or could guide me through an easier way of doing this.

I can provide the model: http://www.roblox.com/Model-item?id=237741478

I can't really explain it any better, please ask questions :)

debouce = false

local shirt = script.Parent.Shirt
local pants = script.Parent.Pants
local face = script.Parent.Face
local hat = script.Parent.Hat

function onTouched(hit)
    if debouce == false then
    local h= hit.Parent:findFirstChild("Humanoid")
        if h~=nil then
        debouce = true
        wait(0.1)
        script.Parent.BrickColor = BrickColor.new("Black")

        local RP=hit.Parent:GetChildren() 
            for i=1,#RP do 
                if RP[i].className=="Pants" then 
                RP[i]:remove() 
                end 
            end

        local RS=hit.Parent:GetChildren() 
            for i=1,#RS do 
                if RS[i].className=="Shirt" then 
                RS[i]:remove() 
                end 
            end

        local RH=hit.Parent:GetChildren()
            for i=1,#RH do 
                if RH[i].className=="Hat" then
                RH[i]:remove()
                end 
            end

        local P = Instance.new("Pants")
        P.Parent = hit.Parent
        P.PantsTemplate = pants.Value

        local S = Instance.new("Shirt")
        S.Parent = hit.Parent
        S.ShirtTemplate = shirt.Value

        local F = hit.Parent.Head.face
        F.Texture = face.Value

        wait(2)
        script.Parent.BrickColor = BrickColor.new("Bright blue")
        debouce = false

        end
    end
end

script.Parent.Touched:connect(onTouched)
0
If I am not mistaken, using the Hat Class made by ROBLOX then parenting this into the players Character model will make said hat attach to the player. If you need an actual script to touch a part and get it from a service, Comment or PM me on ROBLOX. alphawolvess 1784 — 9y
0
Well, I was trying to achieve a Character Customization system which wouldn't be a touch script, but my scripting level isn't that advanced. excellentAnarchy 50 — 9y
0
I'll make a script and show you how to put it inside of the Character from Replicated Storage. My hierarchy probably will differ from yours. alphawolvess 1784 — 9y
0
Will you base it on GUIs? excellentAnarchy 50 — 9y
0
Like you were talking about, from touching a physical Part. alphawolvess 1784 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

This is just a script inside of a part.

debounce = false



script.Parent.Touched:connect(function(Hit)
    if Hit.Parent:FindFirstChild("Humanoid") then -- I use FIndFirstChild() to prevent Errors
        if debounce == false then debounce = true
            local Copy = game.ReplicatedStorage:FindFirstChild("Hat1"):Clone()
            local Char = Hit.Parent -- This is the Character(Model that holds all parts)
            local player = game.Players:GetPlayerFromCharacter(Char) -- So we know WHO to give the Hat
            Copy.Parent = player.Character
            wait(3)
            debounce = false
        end
    end
end)

I used a debounce so you will not get the hat spammed inside of your character. Obviously above, I used the Touched function. I also used GetPlayerFromCharacter so I will know who it is that touched the part and who it is that will receive the hat. If you need more information on this script, then just comment on this Answer.

Plus 1 and Accept if this helped

0
I know how to drop a hat onto a Character, but what I'm trying to achieve is kind of hard to explain, I'll drop you a message on ROBLOX. excellentAnarchy 50 — 9y
0
For some reason when I use this script it teleports the player to the hat that I am trying to use and gets the player stuck in that position. Do you know of any way to stop this from happening? Or if the script is just outdated? Thanks in advance! earlgrey2014 -4 — 3y
Ad

Answer this question