Okay, so there are some noticeable differences. The most obvious one is that print(2) is never printed in the output on the second attempt, which proves that the script isn’t able to destroy. However, it is able to get past the first print(1), which means the issue lies in the second condition. More specifically:
if v.ClassName == "Shirt" and v:IsA("Shirt") then
print(2)
v:Destroy()
end
To translate into English, whatever v is, it definitely isn’t a shirt. If it is, then something is up with your condition (the text between if and then)
Not sure, but as I said at the beginning, I found it really weird that you were checking twice if v was a Shirt. I know you said you fixed that statement already, but here the problem still remains. So, try getting rid of the v.ClassName == "Shirt" and just keep v:IsA("Shirt). There is no need for the former.
shirtButton.MouseButton1Click:Connect(function()
local currentshirt = player:FindFirstChild("OGShirt")
local char = player.Character or player.CharacterAdded:Wait()
local Humanoid = game.Workspace:FindFirstChild(player.Name):FindFirstChild("Humanoid")
if Humanoid and Humanoid.Parent:FindFirstChild("Shirt") == nil then
local p = Instance.new("Shirt", Humanoid.Parent) p.Name = "Shirt"
end
if Humanoid.Parent:FindFirstChild("Shirt") then
Humanoid.Parent.Shirt.ShirtTemplate = currentshirt.Value
end
end)
and the serverscriptservice script
local Cooldown = false
local OriginalStored = false
game.Players.PlayerAdded:Connect(function(player)
local OGshirt = Instance.new("StringValue", player) OGshirt.Name = "OGShirt"
local OGpants = Instance.new("StringValue", player) OGpants.Name = "OGPants"
player.CharacterAdded:Connect(function(char)
wait(1)
local Human = char:FindFirstChild("Humanoid")
if Human and Human.Parent:FindFirstChild("Shirt") == nil then
return
end
if Human and Human.Parent:FindFirstChild("Pants") == nil then
return
end
if Human and Human.Parent:FindFirstChild("Shirt") then
OGshirt.Value = Human.Parent.Shirt.ShirtTemplate -- the value for the players shirt
print(OGshirt.Value)
end
if Human and Human.Parent:FindFirstChild("Pants") then
OGpants.Value = Human.Parent.Pants.PantsTemplate -- value for player's pants
print(OGpants.Value)
Human.Parent.Shirt.ShirtTemplate = OGshirt.Value
Human.Parent.Pants.PantsTemplate = OGpants.Value
Cooldown = true
OriginalStored = true --bool that determines that IDs are stored as varibles
wait(2)
Cooldown = false
end
end)
end)
so I did this with the script, and nothing printed, lol But it still worked the first time I ran the script.
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
local hum = char.Humanoid
for _, v in pairs(char:GetChildren()) do
print(1)
if v:IsA("Shirt") then
print(2)
v:Destroy()
end
end
for key, obj in pairs(char:GetChildren()) do
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)
No, I am using a regular script in the item in workspace. This is the script.
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
local hum = char.Humanoid
for _, v in pairs(char:GetChildren()) do
print(1)
if v:IsA("Shirt") then
print(2)
v:Destroy()
end
end
for key, obj in pairs(char:GetChildren()) do
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)
Something should print. If you mean that print(2) didn’t show up in the output, then that makes sense. But everything else should’ve printed like before.
Assuming that nothing changed with the output, that means that there are literally zero Shirts to destroy.
Try this script, which adds a print statement to show the list of objects within char:GetChildren():
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
print(char:GetChildren())
local hum = char.Humanoid
for _, v in pairs(char:GetChildren()) do
if v:IsA("Shirt") then
v:Destroy()
end
end
for key, obj in pairs(char:GetChildren()) do
if obj:IsA("Accessory") then
local accessory = obj
local handle = obj:FindFirstChild("Handle")
for i,v in pairs(handle:GetChildren()) do
if v.Name == "BodyFrontAttachment" and v:IsA("Attachment") then
accessory:Destroy()
end
end
end
end
local clonedItem = item:Clone()
clonedItem.Handle.Anchored = false
hum: AddAccessory(clonedItem)
end
clicker.MouseClick:Connect(giveAccessory)
no sorry, that is a localscript under screengui. It’s this
shirtButton.MouseButton1Click:Connect(function()
local currentshirt = player:FindFirstChild("OGShirt")
local char = player.Character or player.CharacterAdded:Wait()
local Humanoid = game.Workspace:FindFirstChild(player.Name):FindFirstChild("Humanoid")
if Humanoid and Humanoid.Parent:FindFirstChild("Shirt") == nil then
local p = Instance.new("Shirt", Humanoid.Parent) p.Name = "Shirt"
end
if Humanoid.Parent:FindFirstChild("Shirt") then
Humanoid.Parent.Shirt.ShirtTemplate = currentshirt.Value
end
end)
Actually, try this script instead to see the ClassName of v.
This should yield more interesting results.
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
local hum = char.Humanoid
for _, v in pairs(char:GetChildren()) do
print(v.ClassName)
if v:IsA("Shirt") then
v:Destroy()
end
end
for key, obj in pairs(char:GetChildren()) do
if obj:IsA("Accessory") then
local accessory = obj
local handle = obj:FindFirstChild("Handle")
for i,v in pairs(handle:GetChildren()) do
if v.Name == "BodyFrontAttachment" and v:IsA("Attachment") then
accessory:Destroy()
end
end
end
end
local clonedItem = item:Clone()
clonedItem.Handle.Anchored = false
hum: AddAccessory(clonedItem)
end
clicker.MouseClick:Connect(giveAccessory)
i believe that is the issue. you are applying changes locally on the client, which means the server cannot see these changes. This means that when the server goes to make a change from another script, it causes problems because it cant see those changes from the localscript.
The solution would be to use that reset localscript to activate a remote event and then have a normal script detect when it goes off and then apply the changes there.
Changes made in localscripts are only visible to the client, not the server or other players. for these new changes to work, they must be done on the server.
So when I clicked the new shirt for the first time, here is the output
15:46:28.414 Part - Server - giveAcc:11
15:46:28.415 Pants - Server - giveAcc:11
15:46:28.415 MeshPart (x5) - Server - giveAcc:11
15:46:28.415 Shirt - Server - giveAcc:11
15:46:28.416 MeshPart (x6) - Server - giveAcc:11
15:46:28.417 Humanoid - Server - giveAcc:11
15:46:28.417 Script - Server - giveAcc:11
15:46:28.417 LocalScript - Server - giveAcc:11
15:46:28.417 BodyColors - Server - giveAcc:11
15:46:28.417 MeshPart (x4) - Server - giveAcc:11
15:46:28.418 Accessory (x2) - Server - giveAcc:11
nothing when I reset the shirt from the screengui prints (because I didn’t put anything in there yet, sorry)
and then when I click the shirt again this is the output
15:47:50.144 Part - Server - giveAcc:11
15:47:50.144 Pants - Server - giveAcc:11
15:47:50.144 MeshPart (x5) - Server - giveAcc:11
15:47:50.145 Accessory - Server - giveAcc:11
15:47:50.145 MeshPart (x6) - Server - giveAcc:11
15:47:50.146 Humanoid - Server - giveAcc:11
15:47:50.146 Script - Server - giveAcc:11
15:47:50.146 LocalScript - Server - giveAcc:11
15:47:50.146 BodyColors - Server - giveAcc:11
15:47:50.146 MeshPart (x4) - Server - giveAcc:11
15:47:50.147 Accessory (x2) - Server - giveAcc:11
Lol, I didn’t actually look at what printed. So looks like only line 11 of the code is working? Which is print ClassName…
But when I hit the reset shirtbutton, it gives me back my original shirt. nothing prints there, but I have my original shirt back on. But it’s not recognizing that the second time I run the script.
its not recognizing it because you reset only on the client and are trying to recognize that with a server script. The server cannot see changes applied only on the client.