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

Debounce certain parts of code?

Asked by 4 years ago

Hey all, I am currently having troubles with debounce. I am attempting to Debounce the first half of my code until the second half is complete. However when I attempt to do this, the code is debounced but the second half doesn't play out. Any reasons why?

local UIS = game:GetService("UserInputService")
local rp = game.ReplicatedStorage
local debounce = false
local unsummon = false
UIS.InputBegan:Connect(function(input,isTyping)
        if isTyping then
            return
        elseif input.KeyCode == Enum.KeyCode.Q then
            if not debounce then
            rp.DefStand.Summon:FireServer()
            debounce = true
            wait(3)
            debounce = false
            end
UIS.InputBegan:Connect(function(input,isTyping)
    if isTyping then
        return
    elseif input.KeyCode == Enum.KeyCode.Q then     
        rp.DefStand.Callbackstand:FireServer()
    end
end)
        end
    end)

Server script

game:GetService("ReplicatedStorage").DefStand.Summon.OnServerEvent:Connect(function(player)
    local sound = workspace.DS_summon
    local Stand = game:GetService("ServerStorage").DefaultStand:Clone()
    local StandModel = Stand.Dummy:Clone()
    local debounce = false

    sound:Play()
    StandModel.Parent = workspace
    if StandModel then
        local function summonWeld()
            local char = player.Character or player.CharacterAdded:Wait() --Error here.
            local weld = Instance.new("WeldConstraint")

            weld.Parent = game.Workspace
            weld.Part0 = char.HumanoidRootPart
            weld.Part1 = StandModel.HumanoidRootPart
        end
        summonWeld()
        StandModel.Position = Vector3.new (player.Character.UpperTorso.Position.X,player.Character.UpperTorso.Position.Y,player.Character.UpperTorso.Position.Z)
    end
end)

game:GetService("ReplicatedStorage").DefStand.Callbackstand.OnServerEvent:Connect(function()
    local Stand = game.Workspace.Dummy
    if Stand then
        local Stand = game.Workspace.Dummy:Destroy()
    end
end)

Answer this question