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

So I am a beginner at scripting? Help please

Im trying to change the material of a brick... This is my script that I made but does not work.

while true do
game.Workspace.Part.Material = (Wood)
wait(1)
game.Workspace.Part.Material = (Foil)
wait(1)

2 answers

✓ Accepted answer

A string is needed, otherwise, Wood and Foil are not defined, so they would be read as nil, you were also missing an end.

Here's the script:

while true do 
	workspace.Part.Material = "Wood"
	wait(1)
	workspace.Part.Material =  "Foil"
	wait(1)
end

Consider reading about strings this will help you understand what strings are and how to use them.

Hope it helps!

3 comments

0

I did mistake the script. I forgot an end and I forgot that it was quotations. But I don't get how u don't say game.Workspace

0

You don't need game.Workspace, that's just typing 5 pointless characters, and this method only works for workspace.

0

game.Workspace is the full path, and you do need the 'game' if you want to access other services, like ServerStorage. However, since workspace is used so often, Roblox has a built in variable for it. It's like saying 'workspace = game.Workspace' at the top of your script, only roblox does it for you.

First of all, loops create scopes. In the output, whenever you see 'end' expected...blah blah... near <eof>, it means you need to put "end" at the end of a scope.

Second, get rid of the parenthesis. Use quotation marks to change properties that want strings. Strings in programming are basically just words, or text in general.

while true do
	workspace.Part.Material = "Wood" --Protip: You can use "workspace" instead of "game.Workspace" to refer to the workspace. That only works for workspace.
	wait(1)
	workspace.Part.Material = "Foil"
	wait(1)
end

More about scopes: http://wiki.roblox.com/index.php?title=Scope

1 comment

1

Ugh you beat me to it! Upvoted!

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