Why doesnt this script work?

Why doesnt this script work?

local platform = script.Parent

local debounce = false

local function hit()
if debounce then
	debounce = true
	
	platform.Transparency = 0.5
	
	wait(5)
	
	platform.Transparency = 0
	
	debounce = false
  end
end

platform.Touched:Connect(hit)

Remove the local before function hit(). Also what @Rynappel said, you logic is flipped. You can use if not debounce or change debounce to be true and flip the other assignments.

Because debounce starts at false so it wont run, set debounce to true

local debounce = false
1 Like

Can you elaborate more? I thought you always need to put a local before defining a variable.

local platform = script.Parent

local debounce = true

function hit()
if debounce then
	debounce = true
	
	platform.Transparency = 0.5
	
	wait(5)
	
	platform.Transparency = 0
	
	debounce = false
  end
end

platform.Touched:Connect(hit)
1 Like

Change this

To this:

if not debounce then

Your OP with the script was checking if the debounce was equal to true, but since you had it at false when you first defined it the if statement just skipped through the rest of the function

1 Like

OHHHHH wait hold on let me try it

Yeah you could do that to, you don’t need to put local before the function (in this case) but you can if you want.

1 Like

Can you also explain what the “if not (plug in something here) then” means?

Its opposite bassically. if not this then if it is false it will continue

Next time, try debugging your self to see if you can solve it, like this:

local platform = script.Parent

local debounce = false

local function hit()
print("Function Hit Fired")
if debounce then
    print("Debounce = true")
	debounce = true
	
	platform.Transparency = 0.5
	
	wait(5)
	
	platform.Transparency = 0
	
	debounce = false
  end
end

platform.Touched:Connect(hit)

Then you could see “Debounce is true” didnt print, and hopefully spot it. :+1:

1 Like

That just basically means the opposite of what you’re trying to check

Like if I put this:

local Yes = true

if not Yes then --This won't pass through because Yes is equal to true, and not false
    print(Yes)
end

if Yes then --This will pass however since Yes is equal to true (Yes = true)
    print(Yes)
end
1 Like