I want the for loop to list through all of the items in a model, then for the if statement to check whether that is there. If it is, it will print "Hello". However, the two aren't comparing correctly using the if statement. Here is my code:
01 | local player = game.Players.LocalPlayer.Name |
02 | local frame = script.Parent.Frame |
03 | local tool = game.Lighting.Crisps |
04 |
05 | for i,v in pairs (frame:GetChildren()) do |
06 | frame:TweenPosition(UDim 2. new( 0.113 , 0 , 0.141 , 0 )) |
07 | v.MouseButton 1 Click:Connect( function () |
08 | local flavour = v |
09 | print (flavour) |
10 | for i,v in pairs (tool:GetChildren()) do |
11 | if v.Name = = flavour then |
12 | print ( "Hello" ) |
13 | end |
14 | end |
15 | end ) |
16 | end |
On line 8, you are setting flavour to be equal to v, which is at the time the Instance
that the for
loop is on.
Let's assume that this Instance
is a TextButton
. You are setting flavour to an object value, not a string value.
On line 11, you're comparing a string value to an object value.
To fix it, just add a ".Name" to the end of "flavour" on line 11.
01 | local player = game.Players.LocalPlayer.Name |
02 | local frame = script.Parent.Frame |
03 | local tool = game.Lighting.Crisps |
04 |
05 | for i,v in pairs (frame:GetChildren()) do |
06 | frame:TweenPosition(UDim 2. new( 0.113 , 0 , 0.141 , 0 )) |
07 | v.MouseButton 1 Click:Connect( function () |
08 | local flavour = v |
09 | print (flavour) |
10 | for i,v in pairs (tool:GetChildren()) do |
11 | if v.Name = = flavour.Name then |
12 | print ( "Hello" ) |
13 | end |
14 | end |
15 | end ) |
16 | end |