Unable to assign property Image. Content expected, got nil

Hello. I am currently making a Find The Memes game and am trying to change the collection GUI to the name of the meme you are collecting. But I get the error(see title) every time I try to collect it.

Here’s the script parented to my GUI:

local ReplicatedStorage = game:GetService(“ReplicatedStorage”)

local RemoteEvents = ReplicatedStorage:WaitForChild(“RemoteEvents”)

local NewMemeCollected = RemoteEvents:WaitForChild(“NewMemeCollected”)

local Frame = script.Parent

local MemeName = Frame:WaitForChild(“MemeName”)

local MemeImage = Frame:WaitForChild(“MemeImage”)

NewMemeCollected.OnClientEvent:Connect(function(name,imageId)

MemeName.Text = name…" "

MemeImage.Image = imageId

Frame.Visible = true

wait(4)

Frame.Visible = false

end)

Let me know if you need more information. Thank you in advance.

can you put the code inside of this?
image

1 Like
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvents = ReplicatedStorage:WaitForChild("RemoteEvents")
local NewMemeCollected = RemoteEvents:WaitForChild("NewMemeCollected")

local Frame = script.Parent
local MemeName = Frame:WaitForChild("MemeName")
local MemeImage = Frame:WaitForChild("MemeImage")

NewMemeCollected.OnClientEvent:Connect(function(name,imageId)
	MemeName.Text = name.." "
	MemeImage.Image = imageId
	Frame.Visible = true
	wait(4)
	Frame.Visible = false
end)

Here’s the code from another script that might help:

local BadgeService = game:GetService("BadgeService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvents = ReplicatedStorage:WaitForChild("RemoteEvents")
local BadgeCollected = RemoteEvents:WaitForChild("BadgeCollected")
local NewMemeCollected = RemoteEvents:WaitForChild("NewMemeCollected")
local meme = script.Parent

local name = "Baller"
local ImageId = "rbxassestid://11151804223"

function debounce(func)
	local isRunning = false
	return function(hit)
		if not isRunning then
			isRunning = true
			func(hit)
			wait(5)
			isRunning = false
		end
	end
end


local function giveBadge(Player, badgeId)
	local success, badgeInfo = pcall(function()
		return BadgeService:GetBadgeInfoAsync(badgeId)
	end)
	if success then
		if badgeInfo.IsEnabled then
			local success, result = pcall(function()
				NewMemeCollected:FireClient(Player, name, ImageId)
				NewMemeCollected:FireClient(Player, name)
				return BadgeService:AwardBadge(Player.UserId, badgeId)
			end)
			if not result then
				BadgeCollected:FireClient(Player)
			end
		end
	end
end	

meme.Touched:Connect(debounce(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local character = hit.Parent
		local Player = game.Players:GetPlayerFromCharacter(character)
		if Player then
			giveBadge(Player, 2129400475)
		end
	end
end))

The error you’re receiving is related to the line that tries to set the image property of the MemeImage object:

MemeImage.Image = imageId

This error is most likely occurring because the imageId value you’re passing in is not a valid image asset ID. Double-check that the imageId variable is actually set to a valid image asset ID before attempting to set it as the Image property of the MemeImage object.

Another possible cause of this error could be that the MemeImage object does not exist in the GUI. Double-check that the name of the object is spelled correctly and that it is a direct child of the Frame object.

If the issue persists, you may want to add some additional error checking code to help diagnose the issue. For example, you could add some print statements to output the value of the imageId variable to the console to see if it is set to a valid value.

The meme.Touched event is connected to a debounce function that waits for 5 seconds before allowing the event to fire again. This can prevent the event from firing multiple times in rapid succession, which can cause issues with the script’s functionality.

When the meme.Touched event fires, the script checks if the object that touched the meme part has a Humanoid child. If it does, the script attempts to award the badge with ID 2129400475 to the player associated with the touching character using the giveBadge function.

If the award is successful, the NewMemeCollected remote event is fired to notify the client that a new meme has been collected, passing the name and image ID of the meme as arguments. The BadgeCollected remote event is fired if the award is not successful.

Overall, this script also seems to be functional and should award the specified badge to players who touch the meme part and successfully enable it.

1 Like

Why is this fired twice?

1 Like

It worked! Thank you so much for your help!

No problem, if it worked please mark as solution.

1 Like

That was part of the problem. Thanks for pointing that out!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.