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

What is wrong with the =?

Asked by 9 years ago
if game.Workspace["EDM MIXER 1"].edmmix.MusicPlayer.PlaylistA.SongA1.Pitch = 1
    then script.Parent.Text = "Value: Even"
elseif game.Workspace["EDM MIXER 1"].edmmix.MusicPlayer.PlaylistA.SongA1.Pitch = 1.1
    then script.Parent.Text = "Value: +1"
end

on the = sign for line one it says expected then near =, and it doesn't work. :/

2 answers

Log in to vote
2
Answered by 9 years ago

Use "==" instead of "=" because "=" is assigning something to another thing, and "==" is comparing two things, which is what you're trying to do.

So if you're trying to set a property to true, you would say:

workspace.Part.Anchored = true

but if you wanted to check if workspace.Part.Anchored = true then you'd say:

if workspace.Part.Anchored == true then
    --code
end
1
You can simply use "if workspace.Part.Anchored then" as the Anchored value is a boolean value so no comparison is needed. User#5423 17 — 9y
Ad
Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

Next time, please put your code in code block. You can do this by clicking the blue lua symbol above the text pad, then put your code inside the numeral tilde keys.



Your problem is that you're using the definition operator for a comparitive statement

= is the definition operator, it's used to define things.

==* is the comparitive operator, it's used to compare whether or not two things are identical to eachother.*



So to fix your code, on the first and third lines then just add one more equal sign(:



(NOTE: You can access the Workspace by just saying workspace. Also, assigning variables can make for much cleaner and faster code - faster meaning you don't have to retype everything)



--Lets make a variable for your song
local songa1 = workspace["EDM MIXER 1"].edmmix.MusicPlayer.PlaylistA.SongA1

--Now we can use the variable here(:
if songa1.Pitch == 1 then 
    script.Parent.Text = "Value: Even" 
elseif songa1.Pitch == 1.1 then 
    script.Parent.Text = "Value: +1"
 end

Answer this question