Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why doesnt this script change an image when its parents texture changes?

local player = game.Players.LocalPlayer

if script.Parent.Texture == "rbxassetid://5651929240" then
	print("works")
	player:WaitForChild(PlayerGui).level.Frame.ImageLabel.Image = "rbxassetid://5651929240"
	player:WaitForChild(PlayerGui).level.Frame.imagetext.Text = "This image is called 65 WAT Meme"
end

This is the Script inside the Decal. No errors execpt it cant find a global PlayerGui in the script, it does not show up in dev console. It wont change the image or text of the ImageLabel or the TextLabel. It does not print works either. The Image isnt moderated, IDK whats going on, please help!

1 comment

2 answers

The conditional is evaluated upon runtime; your if-statement will not evaluate the expressions again unless programmed to.

To do so, we can use the GetPropertyChangedSignal method of the Instance base-class. This will allow us to provide a callback for when the specified property changes:


Regarding "Global 'PlayerGui'":

The WaitForChild method of Instance expects a String, by syntax context, it's assuming you're trying to reference a variable.


--###----------[[SERVICES]]----------###--
local Players = game:GetService("Players")


--###----------[[VARIABLES]]----------###--
local Player = Players.LocalPlayer

local PlayerGui = Player:WaitForChild("PlayerGui")

local LevelGui = PlayerGui:WaitForChild("level")
local LevelFrame = LevelGui:WaitForChild("Frame")

local ImageLabel = LevelFrame:WaitForChild("ImageLabel")
local ImageText = LevelFrame:WaitForChild("imagetext")


local TextureObject = script.Parent


--###----------[[FUNCTIONS]]----------###--
local function AdjustImage()
	if (TextureObject.Texture == "rbxassetid://5651929240") then
		---------------
		ImageLabel.Image = TextureObject.Texture
		---------------
		ImageText.Text = "This Image is called \"65-WAT meme\""
	end
end


--###----------[[SETUP]]----------###--
TextureObject:GetPropertyChangedSignal("Texture"):Connect(AdjustImage)

####Note:

It's a poor practice to leave Instances un-named or named without context. I suggest you give better handles to your Objects, additionally formatted in CameCase. Ensure consistency is applied.

The reason why this doesn't work is that it only checks once, not repeatedly. In this case, you could use :GetPropertyChangedSignal to detect a change and run the function.

local player = game.Players.LocalPlayer

script.Parent:GetPropertyChangedSignal('Texture'):Connect(function()
	if script.Parent.Texture == "rbxassetid://5651929240" then
	print("works")
	player:WaitForChild(PlayerGui).level.Frame.ImageLabel.Image = "rbxassetid://5651929240"
	player:WaitForChild(PlayerGui).level.Frame.imagetext.Text = "This image is called 65 WAT Meme"
	end
end)

Also, let me know if this doesn't work because there is something else I noticed, but I can't confirm it until you let me know,

1 comment

0

What do you purpose the issue is?

This discussion is preserved as it was. New answers, comments, and votes are closed.