local air = script.Parent.Air local earth = script.Parent.Earth local fire = script.Parent.Fire local water = script.Parent.Water
if air.MouseButton1Down:Connect() then print "air chosen"
elseif earth.MouseButton1Down:Connect() then print "earth chosen"
elseif fire.MouseButton1Down:Connect() then print "fire chosen"
elseif water.MouseButton1Down:Connect() then print "water chosen" end
I swear im not this bad at coding... im just being stupid and cant solve this.
There are a ton of mistakes in your code. Let me go over them.
Firstly, it isn't good practice to put all of your variables on a single line of code. Try spacing them out a bit.
Secondly, you should be using WaitForChild
if you are trying to reference objects (if your code is running right when the game starts)
For reference:
local air = script.Parent:WaitForChild('Air') local earth = script.Parent:WaitForChild('Earth') local fire = script.Parent:WaitForChild('Fire') local water = script.Parent:WaitForChild('Water')
Thirdly, you don't need all of those If
and Elseif
statements in your code.
I am going to assume that putting all of those variables into a table would be an easier route for the query that you have, but I am not experienced in the Table
world of scripting yet, so I don't want to provide any false information on that.
Anyways, below should be your fixed code (don't forget to include the variables on top.)
air.MouseButton1Down:Connect(function() print('Air') end) earth.MouseButton1Down:Connect(function() print('Earth') end) fire.MouseButton1Down:Connect(function() print('Fire') end) water.MouseButton1Down:Connect(function() print('Water') end)
Please let me know if that code works or not. Once again plopping all of those into a table would probably be an easier way, but I am still learning about tables so I am not able to give any help in that field.
Anyways I hope this helps, dear friend. ????
You don't need an if-statement at all. You have to use a function. Example:
air.MouseButton1Down:Connect(function() print('Air chosen') end)
earth.MouseButton1Down:Connect(function() print('Earth chosen') end)
...etc.
Hope this helps.