Hello,
I am working on a script that gives you a cloned weapon from serverstorage. However, it keeps cloning multiple times, when it shouldn’t. Any help would be appreciated.
Local script:
local frm = script.Parent
local enabled = false
local selected
for _, button in pairs(frm:GetChildren())do
if button:IsA("TextButton") then
button.MouseButton1Click:Connect(function()
if enabled == false then
enabled = true
selected = button.Name
game:GetService('ReplicatedStorage').Gun:FireServer(selected, button.Name)
frm.Parent.TextLabel.Text = selected
wait(1)
enabled = false
end
end)
end
end
Server script:
local gunevent = game:GetService('ReplicatedStorage').Gun.OnServerEvent:Connect(function(player, selected, name)
for _, v in pairs(player.Backpack:GetChildren()) do
if name == "AR-15" then
if v.Name == "TSR-28" or v.Name == "TSR-29" then
v:Destroy()
local clone = game:GetService('ServerStorage').Guns:FindFirstChild('AR-15'):Clone()
clone.Parent = player.Backpack
else
local clone = game:GetService('ServerStorage').Guns:FindFirstChild('AR-15'):Clone()
clone.Parent = player.Backpack
end
end
end
end)