I wrote this script for a forcefield that changes colour and makes a noise when touched. There is a button that turns it on and off. The transparency bit is therefore needed for this to properly work. Here is the script:
db = false function hit(part) if db then return end if script.Parent.Transparency == 0.6 then script.Parent.hit:Play() script.Parent.BrickColor = BrickColor.new("Institutional white") db = true wait(0.2) script.Parent.BrickColor = BrickColor.new("Bright blue") db = false else return end end script.Parent.Touched:connect(hit)
However, this does not seem to work and the output tells me nothing. The part IS 0.6 transparency when the field is turned on. Can someone help?
EDIT: I changed the script to include a debounce.
Considering nobody seemed bothered and/or capable enough to answer this properly, I figured I should try and work it out myself. After a long time of editing, I realised the Transparency was somehow the problem. So, I merely changed it to:
if script.Parent.Transparency ~= 1 then
That seemed to do the trick.
Thanks me!
use this instead..
function hit(part) script.Parent.hit:Play() script.Parent.BrickColor = BrickColor.new("Institutional white") wait(0.2) script.Parent.BrickColor = BrickColor.new("Bright blue") end script.Parent.Touched:connect(hit)