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

How to make light up when player steps on it?

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


1 comment

0

Code block. Use. Please.

2 answers

✓ Accepted answer

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.

1 comment

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.

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.

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