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

If I run the script and it work for the first then the second time it stop working, what do I do?

Asked by 6 years ago

I use this script

local TimesClicked = 0
script.Parent.mouseClick:connect(function(Player)
if script.Parent.Parent.CanCollide == true then
Player.leaderstats.LifeFormFound.Value = Player.leaderstats.LifeFormFound.Value +1
TimesClicked = TimesClicked +1
if TimesClicked == 1 then 
script.Parent.Parent.Transparency = 1
script.Parent.Parent.CanCollide = false
wait(3)
script.Parent.Parent.Transparency = 0
script.Parent.Parent.CanCollide = true

end
end
end)

for the first time, it works but when I click the brick the second time it did not turn invisible

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

So the code Should be

    local TimesClicked = 0
script.Parent.mouseClick:connect(function(Player)
if script.Parent.Parent.CanCollide == true then
Player.leaderstats.LifeFormFound.Value = Player.leaderstats.LifeFormFound.Value +1
TimesClicked = TimesClicked +1
if TimesClicked ~= 0 and TimesClicked ~= nil then
script.Parent.Parent.Transparency = 1
script.Parent.Parent.CanCollide = false
wait(3)
script.Parent.Parent.Transparency = 0
script.Parent.Parent.CanCollide = true

end
end
end)
0
Thx RainbowBeastYT 85 — 6y
0
Why are you saying TimesClicked ~= nil. TimesClicked is a number, not an object. User#19524 175 — 6y
0
Values can have a value as nil maumaumaumaumaumau 98 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

First of all I would like to note that your code is not indented. Well indented code is necessary for spotting errors before they happen and code readability. The reason you are unable to make it work the second time is because on line 5 you are turning TimesClicked to TimesClicked + 1 every time the event is fired. Because of that line 6 will never get past that == 1 again. Hope this helps and have a great day scripting.

0
@Phlegethon5778 thx it helped, but how do I fix it? Plz help. Thx RainbowBeastYT 85 — 6y

Answer this question