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

Why won't my "Touched" event script work? [SOLVED BY MYSELF]

Asked by
JJ_B 250 Moderation Voter
10 years ago

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:

01db = false
02 
03function hit(part)
04    if db then return end
05    if script.Parent.Transparency == 0.6 then
06        script.Parent.hit:Play()
07        script.Parent.BrickColor = BrickColor.new("Institutional white")
08        db = true
09        wait(0.2)
10        script.Parent.BrickColor = BrickColor.new("Bright blue")
11        db = false
12    else return end
13    end
14 
15 
16script.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.

2 answers

Log in to vote
1
Answered by
JJ_B 250 Moderation Voter
10 years ago

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!

3
Sorry if nobody answered your question! Unfortunately, SH doesn't have that many active members and that is why we are trying to recruit more people for the site. Thanks for posting on SH! DigitalVeer 1473 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

use this instead..

1function hit(part)
2        script.Parent.hit:Play()
3        script.Parent.BrickColor = BrickColor.new("Institutional white")
4        wait(0.2)
5        script.Parent.BrickColor = BrickColor.new("Bright blue")
6    end
7 
8 
9script.Parent.Touched:connect(hit)
0
Perhaps I should have been more clear. I have a button turning the forcefield on and off, so I need the transparency thing. Besides, removing it would not help as I already stated that the part WAS 0.6 transparency. JJ_B 250 — 10y

Answer this question