Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Clicking GUI button gives the same hat over and over?

Asked by 2 years ago

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
0
Hello. I will try to help you! ErtyPL 129 — 2y
0
Add https://www.roblox.com/users/24398509/profile to place so he could help you. ErtyPL 129 — 2y

1 answer

Log in to vote
0
Answered by
SuperPuiu 497 Moderation Voter
2 years ago
Edited 2 years ago

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)
Ad

Answer this question