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

How do I do this?

Asked by 10 years ago

When I make my scripts they all seem to need me to disable then enable then in the explorer properties thing please help. Even if I do what I would consider a good code it still does it like this one I made.

local brick = game.Workspace.Brick

function onTouch(part)
brick.Transparency = 1
wait(1)
brick.Transparency = 0

end

brick.Touched:connect(onTouch)

2 answers

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
10 years ago

Changing the source of a script means absolutely nothing if its old code is already running. One solution if you don't want to disable and enable is to stop writing when the world is currently being simulated.

0
What do you mean by the world is being simulated? Grappler123 10 — 10y
0
If the world is not being simulated then it is paused and no code is running. You think you're editing the code that is running, but you can't do that. The code is read and the read code is run. You're changing the code that gets read after it already has been read, so you have to tell it to read it again. 1waffle1 2908 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

Why are you calling the variable "brick" inside your function when you have already an argument called "part" that passes your brick? Change this:

function onTouch(part)
    brick.Transparency = 1
    wait(1)
    brick.Transparency = 0
end

to this:

function onTouch(part)
    part.Transparency = 1
    wait(1)
    part.Transparency = 0
end

Answer this question