How to restore player accessories after they have been deleted by a local script for a button?
Insert them into a table when the player first join the game
you gonna store it and return it on the client
since its deleted on the client it still exist on the server
so you cant use the server to return back the accessory have been deleted on the client
else the accessory will continue to duplicate on the server
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Button -- Button Path
local StoredAccessories= Humanoid:GetAccessories() -- Update it when needed
local function OnButtonClicked()
for _, Accessory in ipairs(StoredAccessories) do
if Character:FindFirstChild(Accessory.Name) then continue end -- Skips when the accessory is already worn by the character
Humanoid:AddAccessory(Accessory)
end
end
Button.MouseButton1Click:Connect(OnButtonClicked)
How to remove current accessories and then get accessories
local function StoreAccesories()
local StoredAccessories = Humanoid:GetAccessories() -- Update it when needed
for _, Accessory in ipairs(StoredAccessories) do
if Character:FindFirstChild(Accessory.Name) then continue end -- Skips when the accessory is already worn by the character
Humanoid:AddAccessory(Accessory)
end
end
just do that and use the function, like this
Player.Died:Connect(StoreAccesories)
Add a new function after a line?
put the StoreAccesories function bellow the OnButtonClicked function
the script that you gave me? put on?
What i literally just said, Also put it in the same script then it would look like this:
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Button -- Button Path
local StoredAccessories= Humanoid:GetAccessories() -- Update it when needed
local function StoreAccesories()
local StoredAccessories = Humanoid:GetAccessories() -- Update it when needed
for _, Accessory in ipairs(StoredAccessories) do
if Character:FindFirstChild(Accessory.Name) then continue end -- Skips when the accessory is already worn by the character
Humanoid:AddAccessory(Accessory)
end
end
local function OnButtonClicked()
for _, Accessory in ipairs(StoredAccessories) do
if Character:FindFirstChild(Accessory.Name) then continue end -- Skips when the accessory is already worn by the character
Humanoid:AddAccessory(Accessory)
end
end
Button.MouseButton1Click:Connect(OnButtonClicked)
Died is not a valid member of Player “Players.ZariffAdeeb”
what i mean is
Player.Humanoid.Died:Connect(StoreAccesories)
i didnt check if the script wont work, but now i think its completely fixed now
Humanoid is not a valid member of Player “Players.ZariffAdeeb”
mate it’s not remove my recent accessories
OH YEah i made another variable named the same as the other variable on the StoreAccesories function
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Button -- Button Path
local StoredAccessories= Humanoid:GetAccessories() -- Update it when needed
local function StoreAccesories()
StoredAccessories = Humanoid:GetAccessories() -- Update it when needed
for _, Accessory in ipairs(StoredAccessories) do
if Character:FindFirstChild(Accessory.Name) then continue end -- Skips when the accessory is already worn by the character
Humanoid:AddAccessory(Accessory)
end
end
local function OnButtonClicked()
for _, Accessory in ipairs(StoredAccessories) do
if Character:FindFirstChild(Accessory.Name) then continue end -- Skips when the accessory is already worn by the character
Humanoid:AddAccessory(Accessory)
end
end
Button.MouseButton1Click:Connect(OnButtonClicked)
Nah it’s not remove the accessories
you can just remove it on a remove function
local function Remove()
for _, Accessory in ipairs(StoredAccessories) do
if Character:FindFirstChild(Accessory.Name) then continue end -- Skips when the accessory is already worn by the character
Accesory:Destroy()
end
end
sadly still not remove my accessories.
Can we discuss it outside devforum?