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

How to make light up when player steps on it?

Asked by 8 years ago
Edited 8 years ago

I want this brick to light up once a character steps on it. it won't light up! What's wrong with my code?

local s1 = script.Parent
local parent = script.Parent



local function LightUp(part)
    local parent = part.Parent
     if game.parent:GetPlayerFromCharacter(parent) then
        s1.Material = Enum.Material.Neon
    wait(10)
    part.Material = Enum.Material.Plastic
    end
    end


0
Code block. Use. Please. User#6546 35 — 8y

2 answers

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

First of all I would suggest using code blocks in the future, as it was difficult to understand the code from the question itself and I had to format it in studio to read what you were trying to achieve (Lua button next to bold, italics, etc).

As it is a small script, I will help you out with my own code and explain how it works with comments.

The script is as follows:

function LightUp() --The function
    local debounce = false --A boolean variable so that the function won't run multiple times
    if debounce == false then --If the variable (debounce) is false then make the variable true
        debounce = true --Makes the variable true
        script.Parent.Material = "Neon" --Changes the Part to the 'Neon' material
        wait(10) --Delay the script for 10 seconds
        script.Parent.Material = "Plastic" --Changes the Part to the 'Plastic' material
        debounce = false --Makes the variable false
    end
end

script.Parent.Touched:connect(LightUp) --If the part is touched then run the function

Enjoy :-)

Next time I would recommend thinking through your issue more and having a better attempt at coding, as this was weak to begin with.

0
Thank you very much, though after reading the 1st comment I took a step back and looked over what I did wrong. I went to the tutorials and looked over what they did, adapted it to mine. It works now, but I thank you for your post. barkface1 15 — 8y
Ad
Log in to vote
1
Answered by 8 years ago

Stop, think.

You write game.parent:GetPlayerFromCharacter(parent) in your code, and you don't report an error? That means you didn't try. I want you to step back and take a look at this code, consider your issue, and come back with a better attempt before asking a weak question like this.

Answer this question