Need help with script!

Ok, I am a beginner scripter and I soon want to be hired one day. And I was making a basic script and it wasn’t working. Please, help.

The code was…
local function color()

game.Workspace.part1.Material = “Neon”

wait(1)

game.Workspace.part1.Material = “Wood”

end

color()

repeat

color()

until

color() == false
Capture

Are you supposed to make the materials change on touch?

No really as I am trying to make it do it by itself. I know it is a simple change if you want to do it on touch. It is fine if you could tell me how. But I don’t know if it’s the function.

We c’ant really help you if we d’ont know what the script is supposed to do… :wut:

Hey there,
Could you please elaborate on what the script does? It will give us a sense of what is meant for, and it will help us put the script into context.

Thanks. :smile:

on the last line, try:

game.Players.PlayerAdded:Connect(color())
local part = workspace.part1    

local function colorChange()
    part.Material = Enum.Material.Neon
    wait(1)
 	part.Material = Enum.Material.Wood  
	wait(1)
end

while true do
    colorChange()
end

Alright, I couldn’t really decipher what you were trying to code but, this will change the part material every second.

Oh, Okay. What I am trying to do is…When you play the part changes from Wood to Neon forever and ever…

Why not use a while loop to do this? You can use while true do to repeat the function forever.

Also it looks like you are trying to break the code as well, when specifically do you want the script to stop operating?

Simply add another wait statement:

local function colorChange()
    part.Material = Enum.Material.Neon
    wait(1)
 	part.Material = Enum.Material.Wood  
    wait(1) -- Hello there I'm new!
end
while true do -- Use a while loop instead
    colorChange()
end

OHH, THANKS. I really didn’t want the script to end but I didn’t know how to make it go on forever so I felt like I needed to put something.

Try to execute the script when a player join with this :
game.players.PlayerAdded:Connect(function()
Your code
end

AH, alright. Will that make the script run when a person touches or makes it run when the game starts?

Glad to help! :slight_smile: If you do need help on how these loops work, you can always look at AlvinBlox’s channel for help and the dev hub as well.

make sure to solution the post that solves your problem too.

loops: Introduction to Scripting | Documentation - Roblox Creator Hub

Use a touched event on the part you want the player to touch for it to start up that function as well.

It execute when someone joins :happy3:

Why use a function though? It might be just me but i don’t use functions that much. Just try:

while true do
game.Workspace.Part1.Material = "Neon"

wait(0.5)

game.Workspace.Part1.Material = "Smooth Plastic"
end

A function is easier :laughing:

I think functions are simple and they take less time. And thank you!

Functions are just used to help clean up code and call it to execute things easier. I don’t think it is super necessary here as well, but as long as it doesn’t make bad practice, you are fine.

If you need help Message us ! :+1: :wave: