Script only runs once until reset/respawn

Oh, I didn’t mean for you to use my example :laughing:

Try this version of the script with the print statements added:

local button = script.Parent.Button
local clicker = button.ClickDetector
clicker.MaxActivationDistance = 25
local item = script.Parent.Item


local function giveAccessory(player)
	local char = player.Character or player.CharacterAdded:Wait()
	local hum = char:WaitForChild("Humanoid")
	for _, v in pairs(char:GetChildren()) do
		print(1)
		if v.ClassName == "Shirt" and v:IsA("Shirt") then
			print(2)
			v:Destroy()
		end
	end

	for key, obj in pairs(char:GetChildren()) do
		print(3)
		if obj:IsA("Accessory") then
			print(4)
			local accessory = obj
			local handle = obj:FindFirstChild("Handle")
			for i,v in pairs(handle:GetChildren()) do
				print(5)
				if v.Name == "BodyFrontAttachment" and v:IsA("Attachment") then
					print(6)
					accessory:Destroy()
				end
			end
		end
	end
	
	local clonedItem = item:Clone()
	clonedItem.Handle.Anchored = false
	hum: AddAccessory(clonedItem)
end

clicker.MouseClick:Connect(giveAccessory)

shirt-stuff.rbxl (52.3 KB)
Check out this place i made, it might help. I created a physical button that changes your shirt, a physical button that removes it, and a gui button that resets your shirt to your original shirt.

I have been trying to run this for like 20 minutes, sorry. I can’t get the statements to end right. Still trying.

lol, I made that way more complicated than it needed to be. I ran your code and here is the output. I am totally confused now.

14:50:48.677 :arrow_forward: 1 (x8) - Server - giveAcc:11
14:50:48.679 2 - Server - giveAcc:13
14:50:48.679 :arrow_forward: 1 (x16) - Server - giveAcc:11
14:50:48.681 :arrow_forward: 3 (x8) - Server - giveAcc:19
14:50:48.683 4 - Server - giveAcc:21
14:50:48.683 :arrow_forward: 5 (x4) - Server - giveAcc:25
14:50:48.683 :arrow_forward: 3 (x15) - Server - giveAcc:19
14:50:48.687 4 - Server - giveAcc:21
14:50:48.688 :arrow_forward: 5 (x4) - Server - giveAcc:25
14:50:59.261 :arrow_forward: 1 (x24) - Server - giveAcc:11
14:50:59.265 :arrow_forward: 3 (x8) - Server - giveAcc:19
14:50:59.266 4 - Server - giveAcc:21
14:50:59.266 :arrow_forward: 5 (x4) - Server - giveAcc:25
14:50:59.267 :arrow_forward: 3 (x15) - Server - giveAcc:19
14:50:59.271 4 - Server - giveAcc:21
14:50:59.271 :arrow_forward: 5 (x4) - Server - giveAcc:25
14:50:59.272 3 - Server - giveAcc:19
14:50:59.272 4 - Server - giveAcc:21
14:50:59.273 :arrow_forward: 5 (x2) - Server - giveAcc:25
14:50:59.273 6 - Server - giveAcc:27
14:50:59.274 :arrow_forward: 5 (x3) - Server - giveAcc:25

this was after hitting the shirt I wanted once, using the remove shirt button and hitting the same shirt again

I appreciate it, but the thing is I am having a hard time getting any button to remove the Shirt versus removing 3D layered clothing, like attachments/accessories. My shirts and pants in game are all attachments, wherein some players original clothes will be classic and others will be layered, if that makes sense

I think I am just misunderstanding what you are saying. Can you just sum up everything that is supposed to happen when you press the “reset clothes/reset shirt” button?

So here’s what is suppose to happen. Player clicks on a shirt (or pants). The shirt the player is wearing is replaced w/the new shirt. There is a screengui where the player can click reset shirt, and their original shirt when they joined the game is put back on.

This all works the first time I run it. It’s after I reset my shirt to the original and then try to click on a shirt, it does not remove my original shirt anymore. It still adds the new shirt, just on top of my og shirt. Here’s the vid.

1 Like

It would be helpful if you could show the print results for each step of the situation. For example, when you first equip an item fresh from joining the game, show the print results. Then, proceed to the next step of the issue and reset your shirt. Show the print results for that. Then equip another accessory. Show print results. Then finally reset the shirt again and see the print results.

*and make sure to separate each step so we can tell the difference!

this is what happened when I did that. I used your print statements. It appears to be running multiple times. This all happened in a few seconds.

Here is what happens when I just click on the new shirt one time. Nothing else clicked or done
15:10:41.731 :arrow_forward: 1 (x8) - Server - giveAcc:11
15:10:41.732 2 - Server - giveAcc:13
15:10:41.733 :arrow_forward: 1 (x16) - Server - giveAcc:11
15:10:41.735 :arrow_forward: 3 (x8) - Server - giveAcc:19
15:10:41.736 4 - Server - giveAcc:21
15:10:41.736 :arrow_forward: 5 (x4) - Server - giveAcc:25
15:10:41.737 :arrow_forward: 3 (x15) - Server - giveAcc:19
15:10:41.741 4 - Server - giveAcc:21
15:10:41.741 :arrow_forward: 5 (x4) - Server - giveAcc:25

1 Like

Ok, now reset the shirt and equip another accessory and show the print results for that.

quick question, are all changes applied to shirts (creating, destroying, etc.) being done on the server? Or are some changes applied only on the client (local scripts)?

This is what happens after I hit the screengui to reset the shirt

15:10:41.731 :arrow_forward: 1 (x8) - Server - giveAcc:11
15:10:41.732 2 - Server - giveAcc:13
15:10:41.733 :arrow_forward: 1 (x16) - Server - giveAcc:11
15:10:41.735 :arrow_forward: 3 (x8) - Server - giveAcc:19
15:10:41.736 4 - Server - giveAcc:21
15:10:41.736 :arrow_forward: 5 (x4) - Server - giveAcc:25
15:10:41.737 :arrow_forward: 3 (x15) - Server - giveAcc:19
15:10:41.741 4 - Server - giveAcc:21
15:10:41.741 :arrow_forward: 5 (x4) - Server - giveAcc:25

1 Like

putting the new shirt on and destroying the shirt are done on a regular script by clicking the shirt in the workspace.

The storing of the shirttemplate and the reset of the original shirt is done both by a localscript under screengui and a regular script in serverscriptservice

Yes. But your issue is that the accessories don’t remove Shirts after they did once already. So, you want to see the difference in print statements between a regular accessory equip event (you already posted that) and what happens once you try again (which you have not posted yet).

Connect it to event, not wait, it might work, scripts doesn’t work twice soo keep that in mind

does the localscript or the regular script do the actual removal/addition of the shirt when resetting? Like which script has the line of code that deletes the shirt and adds the original one?

And here is the out put after I reset my shirt and try to put a new shirt on again. This is where the original shirt is not removed

15:18:17.747 :arrow_forward: 1 (x8) - Server - giveAcc:11
15:18:17.748 2 - Server - giveAcc:13
15:18:17.748 :arrow_forward: 1 (x16) - Server - giveAcc:11
15:18:17.750 :arrow_forward: 3 (x8) - Server - giveAcc:19
15:18:17.751 4 - Server - giveAcc:21
15:18:17.751 :arrow_forward: 5 (x4) - Server - giveAcc:25
15:18:17.752 :arrow_forward: 3 (x15) - Server - giveAcc:19
15:18:17.755 4 - Server - giveAcc:21
15:18:17.755 :arrow_forward: 5 (x4) - Server - giveAcc:25
15:18:24.147 :arrow_forward: 1 (x24) - Server - giveAcc:11
15:18:24.150 :arrow_forward: 3 (x8) - Server - giveAcc:19
15:18:24.151 4 - Server - giveAcc:21
15:18:24.151 :arrow_forward: 5 (x4) - Server - giveAcc:25
15:18:24.152 :arrow_forward: 3 (x15) - Server - giveAcc:19
15:18:24.155 4 - Server - giveAcc:21
15:18:24.155 :arrow_forward: 5 (x4) - Server - giveAcc:25
15:18:24.156 3 - Server - giveAcc:19
15:18:24.157 4 - Server - giveAcc:21
15:18:24.157 :arrow_forward: 5 (x2) - Server - giveAcc:25
15:18:24.157 6 - Server - giveAcc:27
15:18:24.158 :arrow_forward: 5 (x3) - Server - giveAcc:25

If I don’t reset to the original shirt, and just put on a new shirt, everything will continue to run fine, but here is the output when I do that.

15:19:43.243 http://www.roblox.com/asset/?id=12338372601 - Server - BuyClothesMain:59
15:19:43.243 http://www.roblox.com/asset/?id=10762267855 - Server - BuyClothesMain:63
15:19:43.309 player already has the badge! - Server - Outils:16
15:19:47.177 :arrow_forward: 1 (x8) - Server - giveAcc:11
15:19:47.178 2 - Server - giveAcc:13
15:19:47.178 :arrow_forward: 1 (x16) - Server - giveAcc:11
15:19:47.180 :arrow_forward: 3 (x8) - Server - giveAcc:19
15:19:47.181 4 - Server - giveAcc:21
15:19:47.182 :arrow_forward: 5 (x4) - Server - giveAcc:25
15:19:47.182 :arrow_forward: 3 (x15) - Server - giveAcc:19
15:19:47.185 4 - Server - giveAcc:21
15:19:47.185 :arrow_forward: 5 (x4) - Server - giveAcc:25

so when resetting there is a local script and a server script. I had attached them in the beginning of the thread. Let me know if I should insert them again.