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

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

Asked by 4 years ago

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

3 answers

Log in to vote
0
Answered by 4 years ago

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.

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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!

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

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)
0
wait no, lemme fix this TheKakYTArmy 125 — 4y

Answer this question