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
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.
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.