Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Clicking GUI button gives the same hat over and over?

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

2 comments

0

Hello. I will try to help you!

0

Add https://www.roblox.com/users/24398509/profile to place so he could help you.

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.