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

Why is the debounce i put in the script not working?

This is the script with the debounce:

local hasFlag = false
local Thing = true
local DeBounce = false
function accessBackpack(hit)
	if hit and hit.Parent then
		local chara = hit.Parent
		local player = game.Players:GetPlayerFromCharacter(chara)
		local backpack = player:FindFirstChild("Backpack")
		local flag = backpack:FindFirstChild("RedFlag")
		if flag and flag.Parent == backpack and hasFlag == true then
			return "RedFlag"
		else
			return print("No flag")
		end
	end
end 
script.Parent.RedFlag.Handle.Touched:Connect(function(char)
	if DeBounce == false then 
		DeBounce = true 
		hasFlag = true
		if char and char.Parent then
			local player = game.Players:GetPlayerFromCharacter(char.Parent) 
			if player then--check if they are a player
				if char.Parent:FindFirstChild("Humanoid") then 
					if char.Parent.Humanoid.Health > 0 then--if they are still alive
						print(player.Name .. " has the Red Flag!")
						char.Parent:FindFirstChild("Humanoid").Died:Connect(function()
							print("Person who has flag died!")
							if char.Parent:FindFirstChild("RedFlag") or accessBackpack(char) and hasFlag == true then --if they die and they have the flag in their hand or backpack
								hasFlag = false
								local FlagClone = game:GetService("ServerStorage"):WaitForChild("RedFlag"):Clone()--the flag gets cloned and put into workspace
								FlagClone.Parent = game.Workspace
								FlagClone.Handle.CFrame = CFrame.new(char.Parent.Head.Position)
								FlagClone:WaitForChild("Handle").Anchored = true
								Thing = false
								wait(3)
								Thing = true
								FlagClone.Handle.Touched:Connect(function()
									wait(Thing)
									if FlagClone.Parent.Parent == game.Workspace then
										FlagClone.Handle.Anchored = false
									end
								end)
							end                                      
						end)
					end
				end
			end
		end
	end
	DeBounce = false
end)

The problem is that nothing works after line 18/19 (around there) with the debounce. I've tried print statements and output says no errors. Please help me fix this problem. Btw, I just started learning about debounces today, so I'm not very good at it.

4 comments

0

Read my bio.

0

Is it indenting properly lol

0

Just put Debounce = true and if Debounce = true then Debounce = false. Basically switch it.

0

So just that on line 20?

1 answer

local hasFlag = false
local Thing = true
local DeBounce = false

function accessBackpack(hit)
    if hit and hit.Parent then
        local chara = hit.Parent
        local player = game.Players:GetPlayerFromCharacter(chara)
        local backpack = player:FindFirstChild("Backpack")
        local flag = backpack:FindFirstChild("RedFlag")
        if flag and flag.Parent == backpack and hasFlag == true then
        return "RedFlag"
        else
            return print("No flag")
        end
    end
end 

script.Parent.RedFlag.Handle.Touched:Connect(function(char)
    if DeBounce == false then 
    DeBounce = true 
    hasFlag = true
    if char and char.Parent then
        local player = game.Players:GetPlayerFromCharacter(char.Parent) 
        if player then--check if they are a player
            if char.Parent:FindFirstChild("Humanoid") then 
                if char.Parent.Humanoid.Health > 0 then--if they are still alive
                    print(player.Name .. " has the Red Flag!")
          char.Parent:FindFirstChild("Humanoid").Died:Connect(function()
       print("Person who has flag died!")
    if char.Parent:FindFirstChild("RedFlag") or accessBackpack(char) and hasFlag == true then --if they die and they have the flag in their hand or backpack
    hasFlag = false
    local FlagClone = game:GetService("ServerStorage"):WaitForChild("RedFlag"):Clone()--the flag gets cloned and put into workspace
        FlagClone.Parent = game.Workspace
        FlagClone.Handle.CFrame = CFrame.new(char.Parent.Head.Position)
        FlagClone:WaitForChild("Handle").Anchored = true
        Thing = false
        wait(3)
        Thing = true
 FlagClone.Handle.Touched:Connect(function(char2)
    wait(Thing)
    if FlagClone.Parent.Parent == game.Workspace then
        FlagClone.Handle.Anchored = false
        DeBounce = false
    end
end)

    end                                      
end)

                end
            end
        end
    end
wait(2)
end
end)

So, on line 20, you said "if not debounce then". That means if debounce doesnt exists, do this. But it does exsist, so it just skips over it because it doesn't have to do the if statement. I changed it to "if debounce == false" to check if debounce is false.

2 comments

0

I did that and it still doesn't work

0

I cant see any error, past that. Tell me what prints aren't printing, etc. Try removing the debounce system and see if it works. I cant realy help past this.

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