I am really looking for an OnTouch change pants and shirts script, I couldn’t find it in the roblox library and my scripts didn’t work.
2 Likes
If you have an attempt can you please post them? It will be hard to help you without an attempt. We won’t write them for you.
and please don’t make up an excuse like “i deleted it”
1 Like
Alr, I’m opening the studio rn here it is:
---//Variables\\---
local Player = game.Players.LocalPlayer
local NewShirt = script.Parent.Shirt
local NewPants = script.Parent.Pants
------
function OnTouched()
Player.Shirt:Destroy()
Player.Pants:Destroy()
local CloneP = NewPants:Clone()
CloneP.Parent = Player
local CloneS = NewShirt:Clone()
CloneS.Parent = Player
end
script.Parent.TouchPart.OnTouched:Connect(OnTouched)
First off, LocalPlayer
is nil to the server. The server simply has no concept of a “local player”.
Second off not all players have shirts and instead use colored body parts (like me) so you will have to account for that.
Lastly the name of the event is Touched not OnTouched.
---//Variables\\---
local Players = game:GetService("Players")
local new_shirt = script.Parent.Shirt
local new_pants = script.Parent.Pants
script.Parent.TouchPart.Touched:Connect(function(part)
local player = Players:GetPlayerFromCharacter(part.Parent)
if player then -- if a player actually touched the part...
local shirt = player.Character:FindFirstChild("Shirt")
if shirt then -- they have a shirt...
shirt.ShirtTemplate = new_shirt.ShirtTemplate
else -- they don't...
local new = Instance.new("Shirt")
new.ShirtTemplate = new_shirt.ShirtTemplate
new.Parent = player.Character
end
end
local pants = player.Character:FindFirstChild("Pants")
if pants then -- they have pants...
pants.PantsTemplate = new_pants.PantsTemplate
else -- they don't...
local new = Instance.new("Pants")
new.PantsTemplate = new_pants.PantsTemplate
new.Parent = player.Character
end
end)
2 Likes
Thanks for helping me out with the scripts, and it’s a pitty I can just choose one solution, but both are ok I believe.