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

How to make light turn on after a number of touches?

How would I make a script where after touching a block (lets say 10 times) will turn on?

3 answers

add a script to your light part (not the pointlight itself), and then type this in the script

script.Parent.Parent.PointLight.Enabled = false
local touched = 0

script.Parent.Touched:Connect(function(player)

touched = touched + 1

	if touched < 10 then

		
		else

			script.Parent.Parent.(LightName).Enabled = true

	end
	

end)

See if this works! If it doesn't, tell me.

Thanks for the reply! I've figured it out. Originally I had the second conditional statement outside of the function, but once I put it inside it worked.

local timesTouched = 0
script.Parent.PointLight.Enabled = false

script.Parent.Touched:Connect(function(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent) then
		timesTouched = timesTouched + 1
		if timesTouched >= 10 then
			script.Parent.PointLight.Enabled = true
		end
	end
end)

If there is anything I can do to make this better please let me know as I am pretty new to scripting!

Simple enough.. I think I got it right.

local part = --your part
 
touchend = 0

function TurnLightOn()
	--add a script that turns the light on idk
end

function onPartTouched(otherPart)
	touchend = touchend + 1
end

if touchend >= 9 then
	TurnLightOn()
end
 
part.Touched:Connect(onPartTouched)

1 comment

0

wait no, lemme fix this

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