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

How to change clothes every time player spawns?

Asked by 5 years ago

Hi, i've been trying to make it so that every time a character spawns, their pants turn into this: https://www.roblox.com/catalog/3327167553/Green-Pajamas. However, I've been trying lots of different things but i'm way too inexperienced with Roblox Studio/Lua scripting to know what i'm doing (This is my first time attempting to script on Roblox/Lua ever). Where should I put my code to make this happen? What should my code be? What kind of script (local, regular, etc) do I need to use to make this happen?

My main attempt was this:

local function givePajamas(player)
    local character = player.Character
    if character then 
        -- look for pants
        local pants = character:FindFirstChildOfClass("Pants")
        -- create pants if they don't exist
        if not pants then 
            pants = Instance.new("Pants", character)
        end
        -- reset pants content id
        pants.PantsTemplate = "https://www.roblox.com/catalog/3327167553/Green-Pajamas"
    end
end

givePajamas()

I put this code as a local script inside of StarterCharacterScripts. I tried to use the ROBLOX Dev API Reference on their website to help me out (which is where I got the bulk of this code from) but nothing has seemed to work.

Appreciate any help, thank you very much!

1 answer

Log in to vote
3
Answered by 5 years ago

First of all, it needs to be a Script, not a Local Script, or else other players wont see it. Also when you do: givepijamas(), since your function requires a player, and you're firing with nothing, it wont work. Make it a normal Script and put this in:

repeat wait() until script.Parent ~= nil

if not game.Players:GetPlayerFromCharacter( script.Parent ) then return end

local Character = script.Parent

if Character:FindFirstChild( "Pants" ) then
    Character.Pants.PantsTemplate = "rbxassetid://3327167536"
end

also, the pants can't be catalog links, they have to be textures.

1
Hey man! Thank you so much for the help! 567koala 10 — 5y
0
It'd be great if you accepted this answer! RafaelFixe1 108 — 5y
Ad

Answer this question