generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: How do I add debounce to this?

Previous Thread :: Next Thread 
Randy_Moss is not online. Randy_Moss
Joined: 05 Aug 2009
Total Posts: 30511
24 Jun 2016 01:42 PM
script.Parent.Touched:connect(function(h)
if h.Parent:FindFirstChild("Humanoid") then
script.Parent.Transparency = 0
end
end)

script.Parent.TouchEnded:connect(function(h)
if h.Parent:FindFirstChild("Humanoid") then
script.Parent.Transparency = 1
end
end)


I want it so when you are still touching the brick the transparency will be 0, but even the slightest movement triggers touch ended..


Report Abuse
Inigo18 is online. Inigo18
Joined: 02 Feb 2014
Total Posts: 1041
24 Jun 2016 01:46 PM
local a = false
local b = false

script.Parent.Touched:connect(function(h)
if h.Parent:FindFirstChild("Humanoid") then
if a == false then
a = true
script.Parent.Transparency = 0
end
end
end
wait(3)
b = true
end)

script.Parent.TouchEnded:connect(function(h)
if h.Parent:FindFirstChild("Humanoid") then
if b == true then
script.Parent.Transparency = 1
end
end
a = false
b = false
end)
Report Abuse
Randy_Moss is not online. Randy_Moss
Joined: 05 Aug 2009
Total Posts: 30511
24 Jun 2016 01:48 PM
Expectend ) to close ( at line 4 instead got wait


Report Abuse
Skellobit is not online. Skellobit
Joined: 13 Apr 2016
Total Posts: 12758
24 Jun 2016 01:50 PM
then fix it

Formerly ToxicDominator - add 17,509 posts | :(){:|:&};:
Report Abuse
Randy_Moss is not online. Randy_Moss
Joined: 05 Aug 2009
Total Posts: 30511
24 Jun 2016 01:52 PM
trying to, but it doesn't go back to 1 transparency


Report Abuse
Randy_Moss is not online. Randy_Moss
Joined: 05 Aug 2009
Total Posts: 30511
24 Jun 2016 01:56 PM
so yea it's not working .


Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
24 Jun 2016 01:58 PM
There's an extra end in the first bit of code


Report Abuse
Randy_Moss is not online. Randy_Moss
Joined: 05 Aug 2009
Total Posts: 30511
24 Jun 2016 01:59 PM
when I remove it, it still doesn't work


Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
24 Jun 2016 01:59 PM
"it"

which one

Also this is not the best way to debounce this


Report Abuse
Randy_Moss is not online. Randy_Moss
Joined: 05 Aug 2009
Total Posts: 30511
24 Jun 2016 01:59 PM
when I touch the brick the transparency goes to 0 but when I stop, it doesn't revert back to 1


Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
24 Jun 2016 02:03 PM
debounce = true

script.Parent.Touched:connect(function(h)
if debounce then return end
debounce = false
if h.Parent:FindFirstChild("Humanoid") then
script.Parent.Transparency = 0
end
script.Parent.TouchedEnded:connect(function(h)
if h.Parent:FindFirstChild("Humanoid") then
script.Parent.Transparency = 1
debounce = true
end
end)
end)

-- try this?


Report Abuse
Randy_Moss is not online. Randy_Moss
Joined: 05 Aug 2009
Total Posts: 30511
24 Jun 2016 02:03 PM
the second part, the brick goes visible when u touch it but when ur not touching it, it should be invisible but it isn't.


Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
24 Jun 2016 02:06 PM
this maybe?

debounce = true

script.Parent.Touched:connect(function(h)
if debounce then return end
if h.Parent:FindFirstChild("Humanoid") then
debounce = false
script.Parent.Transparency = 0
end
end)

script.Parent.TouchedEnded:connect(function(h)
if h.Parent:FindFirstChild("Humanoid") then
debounce = true
script.Parent.Transparency = 1
end
end)




Report Abuse
Randy_Moss is not online. Randy_Moss
Joined: 05 Aug 2009
Total Posts: 30511
24 Jun 2016 02:06 PM
didn't work


Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
24 Jun 2016 02:07 PM
Oh Haha! Debounce gets confused in my brain. I just messed them up is all:

debounce = false

script.Parent.Touched:connect(function(h)
if debounce then return end
if h.Parent:FindFirstChild("Humanoid") then
debounce = true
script.Parent.Transparency = 0
end
end)

script.Parent.TouchedEnded:connect(function(h)
if h.Parent:FindFirstChild("Humanoid") then
debounce = false
script.Parent.Transparency = 1
end
end)



Report Abuse
Randy_Moss is not online. Randy_Moss
Joined: 05 Aug 2009
Total Posts: 30511
24 Jun 2016 02:08 PM
That works up until a point, I touch the brick, it turns visible, I stop touching the brick, it's still visible when it should be invisible.


Report Abuse
Skellobit is not online. Skellobit
Joined: 13 Apr 2016
Total Posts: 12758
24 Jun 2016 02:10 PM
it's TouchEnded not TouchedEnded

Formerly ToxicDominator - add 17,509 posts | :(){:|:&};:
Report Abuse
DevVince is not online. DevVince
Joined: 08 Nov 2008
Total Posts: 9245
24 Jun 2016 02:11 PM
--Distance of vectors for the win!
script.Parent.Touched:connect(function(hit)
while (hit.Position - script.Parent.Position).Magnitude <= script.Parent.Size.Magnitude do
wait(0.3)
script.Parent.Transparency = 0
end
script.Parent.Transparency = 1
end)
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
24 Jun 2016 02:13 PM
Either magnitude or GetTouchingParts()


Report Abuse
DevVince is not online. DevVince
Joined: 08 Nov 2008
Total Posts: 9245
24 Jun 2016 02:14 PM
--Faster response time:
script.Parent.Touched:connect(function(hit)
while (hit.Position - script.Parent.Position).Magnitude <= script.Parent.Size.Magnitude do
script.Parent.Transparency = 0
wait(0.3)
end
script.Parent.Transparency = 1
end)
Report Abuse
Randy_Moss is not online. Randy_Moss
Joined: 05 Aug 2009
Total Posts: 30511
24 Jun 2016 02:14 PM
Dev that didn't work, it turned visible but not invisible.

btw I fixed it so it was TouchEnded, it worked but, it's still not smooth and if you run across the wall it starts blinking visible/invisible


Report Abuse
DevVince is not online. DevVince
Joined: 08 Nov 2008
Total Posts: 9245
24 Jun 2016 02:16 PM
Just tested, it works fine.
Report Abuse
DevVince is not online. DevVince
Joined: 08 Nov 2008
Total Posts: 9245
24 Jun 2016 02:17 PM
Maybe a higher delay.
script.Parent.Touched:connect(function(hit)
while (hit.Position - script.Parent.Position).Magnitude <= script.Parent.Size.Magnitude do
script.Parent.Transparency = 0
wait(0.5)
end
script.Parent.Transparency = 1
end)
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
24 Jun 2016 02:17 PM
TouchEnded* apparently

Could it be better to disconnect?

debounce = true

function Touch(hit)
if hit.Parent:FindFirstChild("Humanoid") then
connectionTouched:Disconnect()
debounce = false
script.Parent.Transparency = 0
end
end

function TouchEnded(hit)
if debounce == false then
if hit.Parent:FindFirstChild("Humanoid") then
script.Parent.Transparency = 1
wait(3)
debounce = true
connectionTouched = script.Parent.Touched:connect(Touched)
end
end
end


connectionTouched = script.Parent.Touched:connect(Touched)
connectionTouchEnded = script.Parent.TouchEnded:connect(TouchedEnded)


Report Abuse
Randy_Moss is not online. Randy_Moss
Joined: 05 Aug 2009
Total Posts: 30511
24 Jun 2016 02:18 PM
I'm using a normal brick, put the script in it, I touched it, became visible.

Moved away still visible but it should be invisible. What happened to u


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image