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
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?
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)
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.
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