Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I create a Block that changes a players costume (including hat/hair)?

Hey, I've only been using Roblox Studio for 2 days, and if I do say so myself, I am pretty quick at learning it. However for a game I am developing, I require a change of costume part of the way through.

Information on the game: Game style: Explore a World/Map Max player count: 60 (not sure how useful that info is)

Specifics on question: I am designing a room that has "Bio-Hazardous" fog, meaning they have to wear Hazmat suits, I already have an idea on the Costume parts (Top: 4427772288 Trousers/pants: 1273401468 Hood/accessory: 4753158721 Facemask/accessory: 4708697945) - if anybody knows of a better combo, please let me know.

The change of clothes will be achieved by passing through an invisible block (Anchored ticked, CanCollide unticked, transparency 1) that will be on the inside of the doorway, and when they leave, the player will pass through another one that will revert their character.

I have looked up many tutorials, and found different codes that work for some parts, yet not others. I believe the main issue is to do with finding the .LocalPlayer

here are some examples of the code I have tried

This was the shortest but most confusing:

local Part = script.Parent
local Debounce = false

Part.Touched:Connect(function(Hit)
	if not Debounce then
		if Hit.Name == "Humanoid" then
			Debounce = true
			--do something
			print('Hit successfull')
		end
	end
end)

Part.TouchEnded:Connect(function(Hit)
	if Debounce then
		if Hit.Name == "Humanoid" then
			Debounce = false
			--do something
			print('Hit still successful')
		end
	end
end)

This was taken from a YouTube video that was made in 2016 when remove was still an option


script.Parent.Touched:Connect(function(hit)
	if (hit.Parent:FindFirstChild("Huminoid"))then
		local plr = game.Players.FindFirstChild(hit.Parent.Name)
		
		local plrPants = hit.Parent.FindFirstChild("Pants")
		if (plrPants)then
			part.Destroy()
		end
		
		local plrShirt = hit.Parent.FindFirstChild("Shirt")
		if (plrShirt)then
			part.Destroy()
		end
		
		local newclothingpants = "rbxassetid://1273401468"
		local newclothingshirt = "rbxassetid://4427772288"
		
		newclothingpants.Parent = hit.Parent
		newclothingshirt.Parent = hit.Parent
	end
end)

This final one was an edit from a similar article on this website, however caused the most error messages


local Players = game:GetService("Players")
local player = Players.LocalPlayer
print('Is this working')



local PlayerHazmatClothingShirt = 4427772288 -- Put Shirt ID here
local PlayerHazmatClothingPants = 1273401468 -- Put Pants ID here

local function Parent.Parent.ClothesChanger.Touched:Connect(function(hit)
	print('Hit successfull')
    if game.Players.LocalPlayer.Character:FindFirstChild("Shirt") then
        game.Players.LocalPlayer.Character.Shirt:Destroy()
    end
    if game.Players.LocalPlayer.Character:FindFirstChild("Shirt Graphic") then
        game.Players.LocalPlayer.Character:FindFirstChild('Shirt Graphic'):Destroy()
    end
    if game.Players.LocalPlayer.Character:FindFirstChild("Pants") then
        game.Players.LocalPlayer.Character.Pants:Destroy()
    end
	print('destroy successful')
    local newShirt = Instance.new('Shirt',game.Players.LocalPlayer.Character)
    local newPants = Instance.new('Pants',game.Players.LocalPlayer.Character)

    newShirt.ShirtTemplate = "rbxassetid://"..tostring(PlayerHazmatClothingShirt-1) -- tostring converts the number into text.
        newPants.PantsTemplate = "rbxassetid://"..tostring(PlayerHazmatClothingPants-1)
    print('load successfull')
	wait(3)
end 

end)

If anybody knows how to do this it would be a great help

[Other info:] Script is in a model "HazmatCostume" that also includes part "ClothesChanger" and "ClothesReverter"

All objects have Archivable ticked if that helps.

I have tested using the Play here button in Roblox Studio and also the Start server option, however they both come up with the same errors/issues

Apologies I haven't been able to place any screenshots as I don't actually know how to.

1 comment

0

you can use this for the screenshots and put the link to the screenshot/video (it also does videos!) though there might be a better option so research into it (link https://gyazo.com/ sorry if you cant download it!)

1 answer

I think 2 things are wrong with this either:

A. Your using a script and you are calling local player

or

B. The scripts are outdated and not working, in turn not changing the outfit

Here is what script I think will work (local script and script compatible)

local ClothesChanger = script.Parent.ClothesChanger
local ClothesReverter = script.Parent.ClothesReverter
local shirt = script.Shirt -- Put shirt you want in the script
local pants = script.Pants -- Put pants you want in the script
local accessory1 = script.Accessory1 -- Put accessory1 (mask or hood) in script
local accessory2 = script.Accessory2-- Put accessory2 (oppisite of accessory1 for example if accessory1 was the mask put the hood) in script

ClothesChanger.Touched:Connect(function(hit)
	if hit.Parent.Humanoid ~= nil then	
		if hit.Parent.Shirt ~= nil then
			local OriginalShirtCopy = hit.Parent.Shirt:Clone()
			hit.Parent.Shirt.ShirtTemplate = shirt.ShirtTemplate
			ClothesReverter.Touched(function()
				hit.Parent.Shirt:Destroy()
				OriginalShirtCopy.Name = "Shirt"
				OriginalShirtCopy.Parent = hit.Parent
			end)
		else
			local HasmatShirtClone = shirt:Clone()
			HasmatShirtClone.Parent = hit.Parent
			ClothesReverter.Touched(function()
				hit.Parent.Shirt:Destroy()
			end)
		end
		if hit.Parent.Pants ~= nil then
			local OriginalPantsCopy = hit.Parent.Pants:Clone()
			hit.Parent.Pants.PantsTemplate = pants.PantsTemplate
			ClothesReverter.Touched(function()
				hit.Parent.Pants:Destroy()
				OriginalPantsCopy.Name = "Pants"
				OriginalPantsCopy.Parent = hit.Parent
			end)
		else
			local HasmatPantsClone = pants:Clone()
			HasmatPantsClone.Parent = hit.Parent
			ClothesReverter.Touched(function()
				hit.Parent.Pants:Destroy()
			end)
		end
		local Accessory1Clone = script.Accessory1:Clone()
		local Accessory2Clone = script.Accessory2:Clone()
		Accessory1Clone.Parent = hit.Parent
		Accessory2Clone.Parent = hit.Parent
		ClothesReverter.Touched(function()
			Accessory1Clone:Destroy()
			Accessory2Clone:Destroy()
		end)
	end
end)

1 comment

0

I tried this, however nothing happened ,I believe it is to do with how I inserted the Roblox asset id, should I have it as one of the following or something else? local shirt = 4427772288 local pants = script.Pants("rbxassetid://1273401468") local accessory1 = script.Accessory1"4753158721"

This discussion is preserved as it was. New answers, comments, and votes are closed.