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

? The script stops working after a few attempts

Asked by 6 years ago

in my gui, when the player presses X it destroys the item but after a few times it stops working. i dont know why

local script:

player = game.Players.LocalPlayer
Gui = script.Parent.Parent
Debounce = false
game:GetService('UserInputService').InputBegan:connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.X then
        if player.Name == workspace.TestTycoon.Owner.Value then
            if not Debounce then
            Debounce = true 
            local Event = game.ReplicatedStorage:WaitForChild("PickUp1")
            Event:FireServer()
            Gui.Visible = false

            script.Parent.Parent.Close.LocalScript.Disabled = true
            script.Parent.Parent.Move.LocalScript.Disabled = true
            script.Parent.Parent.PickUp.LocalScript.Disabled = true

            wait(0.5)
            player.PlayerGui.TestGui.ClientPlacement.Disabled = false
            player.PlayerGui.TestGui.HitboxHandler.Disabled = false
            player.PlayerGui.TestGui.LocalScript.Disabled = false

            Debounce = false
            end
        end
    end
end)

script:

Event = game:GetService("ReplicatedStorage").PickUp

debounce2 = true


function destroyItem(player)
    if debounce2 then
        debounce2 = false
    for i, v in pairs(script.Parent.TestItems:GetChildren()) do
        if v.MouseOver.Value == true then
            player.PlayerItems:FindFirstChild(v.Name).Value = player.PlayerItems:FindFirstChild(v.Name).Value + 1
            v:Destroy()
    print("Item deleted")
            wait(0.2)
            debounce2 = true
            end
        end
    end
end

Event.OnServerEvent:connect(destroyItem)

Answer this question