Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

3 comments

0

Thx

0

Why are you saying TimesClicked ~= nil. TimesClicked is a number, not an object.

0

Values can have a value as nil

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.

1 comment

0

@Phlegethon5778 thx it helped, but how do I fix it? Plz help. Thx

This discussion is preserved as it was. New answers, comments, and votes are closed.