beloxy
|
  |
| Joined: 14 Aug 2010 |
| Total Posts: 2800 |
|
|
| 18 Jun 2014 06:49 PM |
Yeah, so after staring at scripts for years aweing, a decided to try and figure this stuff out. I want to make a brick that blinks when I touch it. After some help from a friend, I got this far:
local MagicBrick = game.Workspace.Part function onTouch (part) while true do MagicBrick.Transparency = 1 wait(.5) MagicBrick.Transparency = 0 wait (.5) MagicBrick.Touched:connect(onTouch) end
Not sure what's wrong with it.
Thanks,
-Bel |
|
|
| Report Abuse |
|
|
|
| 18 Jun 2014 06:52 PM |
Your connection line needs to be after the 'end' and you need one more end
-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::] |
|
|
| Report Abuse |
|
|
Coopertow
|
  |
| Joined: 18 Apr 2012 |
| Total Posts: 1959 |
|
|
| 18 Jun 2014 06:55 PM |
| hmm A Brick When you Touch it? |
|
|
| Report Abuse |
|
|
beloxy
|
  |
| Joined: 14 Aug 2010 |
| Total Posts: 2800 |
|
|
| 18 Jun 2014 06:55 PM |
Thanks for responding. So two more things. First, here's the correction that has yet to work:
local MagicBrick = game.Workspace.Part function onTouch (part) while true do MagicBrick.Transparency = 1 wait(.5) MagicBrick.Transparency = 0 wait (.5) end MagicBrick.Touched:connect(onTouch) end
And I have no idea what the "MagicBrick.Touched:connect(onTouch)" means. A friend said to add it.
Thanks!
-Bel |
|
|
| Report Abuse |
|
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 18 Jun 2014 06:58 PM |
local db = false
game.Workspace.Part.Touched:connect(function(hit) if db == fals then db = true end local s = Instance.new("StringValue",game.Players:GetPlayerFromCharacter(hit.Parent)) s.Value = "Touching" while s.Value = "Touching" do for i = 1,10 do game.Workspace.Part.Transparency = i/10 wait(.1) end for i = 1,10 do game.Workspace.Part.Transparency = -i/10 wait(.1) end wait() end game.Workspace.Part.TouchEnded:connect(function() s.Value = "Nil" end) end)
This makes the brick blink when your touching it and when you're not touching it then it stops blinking.. the blinking is a smooth conversion of the transparency but at the same speed as the fast one. Hope you like it(: |
|
|
| Report Abuse |
|
|
|
| 18 Jun 2014 06:59 PM |
Put the connection line outside of all of the ends.
MagicBrick.Touched:connect(onTouch) is the connection line. What this does is wait for the .Touched event to fire (when something touches the brick) and then it runs the function onTouch. Every object has many different events that you can find on the wiki or the object browser.
-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::] |
|
|
| Report Abuse |
|
|
|
| 18 Jun 2014 07:03 PM |
local MagicBrick = workspace.Part
function onTouch(h) while true do MagicBrick.Transparency = 1 wait(.5) MagicBrick.Transparency = 0 wait(.5) end end
MagicBrick.Touched:connect(onTouch)
Okay, you an end, and called the function inside itself, which won't work.
function onTouch(h)
So we're creating a function, but what is it called? It's named onTouch, this can be whatever you want. Now, h is the argument, which you don't need to understand right now, since you're not using it, but it can also be whatever you want.
while true do end
This is a generic loop, we tell it to run for whatever conditions, but since we put 'true', true will always be true.. so it will run forever. (Pointer: ALWAYS put a wait in a forever loop, or it will crash your game/studio. You can do it without waiting like this; while wait() do.)
MagicBrick.Touched:connect(onTouch);
So we are making an event listener, so basically, when the brick is 'Touched', it connects it to the function onTouch, using :connect(). In the parentheses you have to put the name of the function, it can be onTouch, WasTouched, BrickWasTouched, asdf, yolo, swag, sodjsihjfisdjfs, or whatever you want to name the function, as I stated earlier.
I hope I explained this well enough :)
|
|
|
| Report Abuse |
|
|
beloxy
|
  |
| Joined: 14 Aug 2010 |
| Total Posts: 2800 |
|
|
| 18 Jun 2014 07:06 PM |
THANKS A TON. I just realized that it doesn't stop when I release it, so when I touch it again out of sync, it goes all weird xD. Probably a good way to lag out a server lol. Ima try and figure that out myself though. THANKS A TON ONCE AGAIN! You guys are awesome!
-Bel |
|
|
| Report Abuse |
|
|
|
| 18 Jun 2014 07:10 PM |
You could call a debounce function.
debounce(function(part)
end)) |
|
|
| Report Abuse |
|
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 18 Jun 2014 07:50 PM |
| Use my script but I forgot to remove debounce.. so edit that. |
|
|
| Report Abuse |
|
|