Help with Image Changing Script?

Hi, I’m trying to make a script that allows the player to change the image on the TV, however the script always loops while ignoring the If statement after the first go and even then it doesnt show the image on the TV correctly.

I’ve tried to check the Dev Hub but all the questions I could find were about pre-determined Id’s.

local scriptp = workspace:WaitForChild("TVs").Tvparts.ScriptPart.SurfaceGui.Frame.TextBox

while true do
	print("looping "..script.Parent.Image)
	wait(0.5)
	if script.Parent.Image ~= "http://www.roblox.com/asset/?id="..scriptp.Text then
		print("TextDiffer")
		script.Parent.Image = "http://www.roblox.com/asset/?id="..scriptp.Text
		print("Text Changed")
		print(script.Parent.Image)
	end
end

All help is appreciated!~

EDIT:
Okay, New problem, I need a way to somehow get the text from the text box into a variable in a regular script, but the problem seems to be that scripts (other than localscripts) only pick up the default text, rather than text added by the client, any more help would be lovely.

||1.|Instead of using while true do, you may want to use a for loop with a finite number of iterations. That way, the loop will only run as many times as you specify.|

||2.|Instead of using script.Parent.Image, you may want to use script.Parent.SurfaceGui.ImageLabel.Image. Since the Image property belongs to the ImageLabel object, you need to access it directly.|
||3.|When setting the value of Image, make sure that you include the file extension in the URL (e.g. “.png”, “.jpg”, etc.). Otherwise, the image may not load correctly.

local scriptp = workspace.TVs.Tvparts.ScriptPart.SurfaceGui.Frame.TextBox

for i = 1, 10 do
wait(0.5)
if script.Parent.SurfaceGui.ImageLabel.Image ~= “http://www.roblox.com/asset/?id=“..scriptp.Text..”.png” then
script.Parent.SurfaceGui.ImageLabel.Image = “http://www.roblox.com/asset/?id=“..scriptp.Text..”.png
print(“Text changed”)
print(script.Parent.SurfaceGui.ImageLabel.Image)
end
end

I’m a bit confused about the png jpg part, Its asking for id’s of images already on the site if that clarifies anything, could you explain why i would need .png/.jpg if said file extensions arent part of the link normally?

Ignored those, that was an example

Still not getting anything from your script

The script works correctly but keep in mind that loading an image takes a bit of time. Also, it is better to put two images and make one and the other visible and invisible
edit: wait is obsolete
use Task.wait(0.5)

Is the image toggleable? Why are you using a while loop?

Sorry? I don’t quite understand (Tbh i’m half asleep)

If this makes it any more specific, scriptp is a editable text box, not pre-determined ID’s,

local tvImage = script.Parent.Image

while true do
    print("looping "..tvImage)
    wait(0.5)
    if tvImage ~= "http://www.roblox.com/asset/?id="..scriptp.Text then
        print("TextDiffer")
        tvImage = "http://www.roblox.com/asset/?id="..scriptp.Text
        script.Parent.Image = tvImage
        print("Text Changed")
        print(tvImage)
    end
end

This way, the script checks the TV’s current image and updates it as necessary.

Still not getting any changes, only Looping http://www.roblox.com/asset?id= (x etc)

this is with me adding a definition for scriptp btw since your answer forgot it.

Having an ID in the text box from the start still doesnt load the image, it just changes the infinite printing of

“Looping http://www.roblox.com/asset?id=
to include the id at the end, the tv itself doesnt change

Okay, I’ve got half a solution, using Rbxthumb it actually loads the first image, but for any images after the first loop it doesnt.

Okay, New problem, I need a way to somehow get the text from the text box into a variable in a regular script, but the problem seems to be that scripts (other than localscripts) only pick up the default text, rather than text added by the client, any more help would be lovely, I’ll ammend this to my post, too

I don’t understand How actually are you gonna print(script.parent.image)