Scripts just dont work despite doing so before

local a = game.ReplicatedStorage:WaitForChild("A").Cards:FindFirstChild(math.random(1,2))
local c = a:GetChildren()
local e = a.Name .. "s" 
local f = c[math.random(1,#c)]
script.Parent.Image = f.Image
local TweenService = game:GetService("TweenService")

		local TweenInfov = TweenInfo.new(
			0.2,
			Enum.EasingStyle.Exponential,--EasingStyle
			Enum.EasingDirection.In,--Easing direction
			0,--times to repeat
			false,--goes in reverse
			0--delay
		)
local PartProperties = {Position = UDim2.new(script.Parent.Parent:FindFirstChild(e).Position.X.Scale,0,script.Parent.Parent:FindFirstChild(e).Position.Y.Scale,0 ) }
		local Tween = TweenService:Create(script.Parent,TweenInfov,PartProperties)

The game tells me image is not a valid member of workspace “Workspace” on line 6 and the tween just moves forward a tiny bit for some reason. And when I print f, the output is the correct one

Shouldn’t that be

local f = c[math.random(1, #c)]
script.Parent.Image = f

?

1 Like

no, f is an ImageButton, not a string.

Well, what are you trying to get from out of c? All of the Instances in there or just ImageButtons?

1 Like

All of the instances in it are ImageButtons, I wanted it to pick one randomly and copy its image.

Could this be the main source that could be causing it? I don’t see any other reason why it’s doing that unless if you use WaitForChild() for the f variable

1 Like

If I print the variables they all print the correct output.

I found out the error acts as if the script’s parent was the workspace and not the ImageButton its parented to

Oh, did you just need to change the script.Parent.Image to script.Image then to fix it?

No, the error was from another script, which was a copy of the original, so I dont have the issue with the output anymore, but the tween is still broken