I have a GUI and when I click the image label more than once it gives the hat, but in clones! Super annoying, please help!
The GUI buttons have string values under them to reference the hats I want to clone when they press a button.
Server Script Service:
local chooseHats = game.ReplicatedStorage:WaitForChild("ChooseHats") local hatsFold = game.ReplicatedStorage:WaitForChild("Accessories") chooseHats.OnServerEvent:Connect(function(player,fullName) local character = player.Character local accessory = hatsFold:FindFirstChild(fullName) local cloneHat = accessory:Clone() cloneHat.Parent = character end)
Local Script under the main GUI:
local chooseHats = game.ReplicatedStorage:WaitForChild("ChooseHats") local hatsFold = game.ReplicatedStorage:WaitForChild("Accessories") local player = game.Players.LocalPlayer local storedValue = nil for i, v in pairs(script.Parent:GetChildren()) do if v:IsA("ImageButton") or v:IsA("TextButton") then v.MouseButton1Click:Connect(function() local fullName = v:WaitForChild("Accessory").Value chooseHats:FireServer(fullName,player) end) end end
Well, you would have to change a bit server script to:
local chooseHats = game.ReplicatedStorage:WaitForChild("ChooseHats") local hatsFold = game.ReplicatedStorage:WaitForChild("Accessories") chooseHats.OnServerEvent:Connect(function(player,fullName) if not player.Character:FindFirstChild("CustomAccessory") then local character = player.Character local accessory = hatsFold:FindFirstChild(fullName) accessory.Name = "CustomAccessory" -- for deleting it later local cloneHat = accessory:Clone() cloneHat.Parent = character else player.Character.CustomAccessory:Destroy() local character = player.Character local accessory = hatsFold:FindFirstChild(fullName) accessory.Name = "CustomAccessory" local cloneHat = accessory:Clone() cloneHat.Parent = character end end)