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

ImageLabel's image wont change when desired in the localscript?

Im currently working on a naruto game, where you can spin to choose your clan, etc. When the player clicks the button, the 'Clan' value, is turned into the randomly chosen clan. Right now what im trying to do, is find a way to change the imagelabel's image to a logo of the clan. For some reason, this error keeps popping up:

LocalScript:19: attempt to index 'Image'(a string value)

Heres the code;




Clans = {'Uchiha', 'Uzumaki', 'Senju', 'Otsutsuki'}
local player = game.Players.LocalPlayer
local tag = player:WaitForChild'Clan'
local spins = player:WaitForChild'Spins'

script.Parent.MouseButton1Click:connect(function()
	if spins.Value >= 1 then
	spins.Value = spins.Value - 1
	local chosen = math.random(1,4)
	chosenf = Clans[chosen]
	tag.Value = ''..chosenf
	script.Parent.Text = tag.Value
	if script.Parent.Text == 'Uchiha' then
		script.Parent.Parent.ImageLabel.Image.Image = 'rbxassetid://924320031'
	elseif script.Parent.Text == 'Otsutsuki' then
		script.Parent.Parent.ImageLabel.Image.Image = 'rbxassetid://344062616'
	end
	else
		script.Parent.Text = 'Not enough Spins!'
		wait(2)
		script.Parent.Text = chosenf
	end
	wait(2)
end)


Is there any better way to go about this ? Maybe coroutine, or something i can use to fix this error?

1 answer

You have one too many "Image" attributes. The ImageLabel is the instance, and Image is an attribute of that instance.

Your code should look like.

        script.Parent.Parent.ImageLabel.Image = 'rbxassetid://924320031'
    elseif script.Parent.Text == 'Otsutsuki' then
        script.Parent.Parent.ImageLabel.Image = 'rbxassetid://344062616'

This instead.

Also, consider adding parenthesis to your code at the top.

local tag = player:WaitForChild('Clan')
local spins = player:WaitForChild('Spins')

Let us know if there are any other errors.

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