Shirt Error, Help

ooops my bad, i forgot you didnt mentioned plr.character

script.Parent.Parent.ProximityPrompt.Triggered:Connect(function(plr)

	local shirt = script:FindFirstChildOfClass("Shirt")
	local pants = script:FindFirstChildOfClass("Pants")

	plr.leaderstats.Money.Value += -50
	if shirt and pants then
		local character = plr.Character
		local plr_shirt = character:FindFirstChildOfClass("Shirt")
		local plr_pants = character:FindFirstChildOfClass("Pants")
		if plr_pants and plr_shirt then
			plr_shirt.ShirtTemplate = shirt.ShirtTemplate
			plr_pants.PantsTemplate = pants.PantsTemplate
		end
	end
end)

this should work.

It still doesnt work
im very confused


nothing in the output

There’s a few issues with this one.

  • You don’t make sure that leaderstats or money is a thing.
  • You don’t make sure that they have enough money
  • You don’t make sure that character is a thing (or humanoid)
  • You don’t make sure that they’re alive
  • You don’t make sure that their character is close to the object (10-20 studs, so they can’t buy it from 1000 studs away) - This one is picky, so I didn’t include it in my own script. It matters more in simulators or shooting games.
  • You don’t do so Shirt or Pants spawn onto their character if it isn’t there, even though they paid for it to happen

he has point tho, but guys help me im so confused why it doesnt work (but thank you for all your times)

Hi!

The script I posted should work on the server side.

Please make sure that the Prompt is a thing, and that something prints when they trigger the Prompt.

This means the shirt and pants doesnt exists some where.
Put your shirt and pants under the script

script.Parent.Parent.ProximityPrompt.Triggered:Connect(function(plr)

	local shirt = script:FindFirstChildOfClass("Shirt")
	local pants = script:FindFirstChildOfClass("Pants")
	
	if plr.leaderstats.Money.Value >= 50 then
		if plr.Character.Humanoid.Health <= 0 then
			return warn("Cant buy shirt they are already dead")
		end
		plr.leaderstats.Money.Value -= 50
	else
		return warn("Player dont have enough cash.")
	end
	
	if shirt and pants then
		local character = plr.Character
		local plr_shirt = character:FindFirstChildOfClass("Shirt")
		local plr_pants = character:FindFirstChildOfClass("Pants")
		if not plr_pants then
			plr_pants = Instance.new("Pants")
			plr_pants.PantsTemplate = pants.PantsTemplate
		end
		if not plr_shirt then
			plr_shirt = Instance.new("Shirt")
			plr_shirt.ShirtTemplate = shirt.ShirtTemplate
		end
		if plr_pants and plr_shirt then
			plr_shirt.ShirtTemplate = shirt.ShirtTemplate
			plr_pants.PantsTemplate = pants.PantsTemplate
		end
	else
		warn("Shirt and pants cant be found under the script")
	end
end)

@TortenSkjold there i’ve covered few issues you’ve said
And about the last second point, hes using proximity prompt so no need to find player distance from the dummy.

Almost!

But what if either Pants or Shirt was present, when you did your check? :smiley:

Then you just pasted a new Shirt (or Pants) into the character, even though it was present.

I think I know what’s the problem… I think a player cannot be assigned a different clothing unless it’s set to him before he dies…

It gives the shirt and etc but It won’t render it unless the player died and respawned with the shirt

That is not quite correct, but I know where your thought comes from.

Nope. all the same issue (also no output)

It could be something wrong with roblox it self, why dont you try testing the game

Wait nevermind… It didn’t work because you can’t change a shirt by ID only. You have to add rbxassetid:// before it.

That’s why It wasn’t working because It just couldn’t get the clothing template

Try this?

script.Parent.Parent.ProximityPrompt.Triggered:Connect(function(plr)

	local shirt = script:FindFirstChildOfClass("Shirt")
	local pants = script:FindFirstChildOfClass("Pants")
	
	if plr.leaderstats.Money.Value >= 50 then
		if plr.Character.Humanoid.Health <= 0 then
			return warn("Cant buy shirt they are already dead")
		end
		plr.leaderstats.Money.Value -= 50
	else
		return warn("Player dont have enough cash.")
	end
	
	if not shirt then
		return warn("Shirt cant be found under the script")
	end
	if not pants then
		return warn("Pants cant be found under the script")
	end
	
	if shirt and pants then
		local character = plr.Character
		local plr_shirt = character:FindFirstChildOfClass("Shirt")
		local plr_pants = character:FindFirstChildOfClass("Pants")
		if not plr_pants then
			plr_pants = Instance.new("Pants")
			plr_pants.PantsTemplate = pants.PantsTemplate
		end
		if not plr_shirt then
			plr_shirt = Instance.new("Shirt")
			plr_shirt.ShirtTemplate = shirt.ShirtTemplate
		end
		if plr_pants and plr_shirt then
			plr_shirt.ShirtTemplate = shirt.ShirtTemplate
			plr_pants.PantsTemplate = pants.PantsTemplate
		end
	else
		warn("Shirt and pants cant be found under the script")
	end
end)

Nope, still the same :frowning_face:
Still no output

edit: im trying to solve this for 3 hours now
a other edit: guys im not gonna eat, drink or rest UNTIL I GOT THE SCRIPT WORKING\

The reason this was not working was because some roblox shirt ID’s can be changed ingame. Plus you cannot get a shirt template by just simply using it’s ID. You have to reference It’s whole URL To be able to do so. Here’s an example on how to do so

Do the same thing on a pant clothing with a pants template. Also here’s the code I was using modified so you can use it on your game

-- Variables
local Debris = game:GetService("Debris")
local Price = 50
local shirt = Instance.new("Shirt")
local pants = Instance.new("Pants")

pants.PantsTemplate = "http://www.roblox.com/asset/?id=144076759" -- Change To what I've shown in the tutorial for the pants
shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=398635080" -- Change To what I've shown in the tutorial for the shirt

script.Parent.ProximityPrompt.Triggered:Connect(function(plr)

	if plr.leaderstats.Money.Value >= 50 then
		plr.leaderstats.Money.Value -= 50

		if plr.Character:FindFirstChildOfClass("Humanoid") and plr.Character:FindFirstChildOfClass("Humanoid").Health >= 1 then

			Debris:AddItem(plr.Character:FindFirstChildOfClass("Shirt"), 1)
			Debris:AddItem(plr.Character:FindFirstChildOfClass("Pants"), 1)
			shirt.Parent = plr.Character
			pants.Parent = plr.Character

		end
	end
end)

If this does give an error about the leader stats It just simply means I did not select the leaderstats location right.

1 Like

1
you are adding an integer when you can subtract a pos. number
2
the script will always subtract the amount of cash, even if it’s insufficient
3
you are trying to get the shirts from the Player, not the Character
4
why are you trying to get ā€œidsā€ from an instance instead of a string/number

local shirt = script:FindFirstChild("Shirt")
local pants = script:FindFirstChild("Pants")
local cost = 50 --expense

script.Parent.Parent.ProximityPrompt.Triggered:Connect(function(plr)
	local leaderstats = plr.leaderstats --get leaderstats
    if leaderstats then -- if true then
        if leaderstats.Money.Value >= cost then -- if player has enough money to buy
            leaderstats.Money.Value -= cost -- subtract
            plr.Character.Shirt.ShirtTemplate = shirt.ShirtTemplate --get id + get player + paste to player's shirts
	        plr.Character.Pants.PantsTemplate = pants.PantsTemplate
        else -- if agurement is not met
            print("not enough dollars") -- print to output
        end
    end
end)

here’s some stuff you can get to know
if then end -- if loop | if requirement is met then it will do a certain function
example

local val = true
if val == true then
 print("true")
end

if then else(if) end --if requirement is met then it will do a function, but if it doesn't meet it will do another function under the [else] subloop
example

local val = true
if val == true then
    print("true")
    val = false -- turn value to false
else
    print("false")
end

i hope these helped!

Try this. I have proof and code made so you can use your script efficiently. Hopefully this helps since as you can see in the video it works for me.