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

How to make the image on BillboardGui change?

Everything work normally except that the image on a variable Left and Right Won't change

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local Overheads = ReplicatedStorage:WaitForChild("OverheadsGui")
local IDVIP = 91491857		----//VIP ID
local GroupId = 11540689	----// GROUP ID

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		-- These variables are used regardless of whether the user owns the gamepass or not
		-- so we can define them outside the if statement
		local Humanoid = Character:WaitForChild("Humanoid")
		local Head = Character:WaitForChild("Head")
		
		local Stats = Player:WaitForChild("leaderstats").Rank.Value
	
		-- Again, this happens regardless of the if statement
		Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
		if
			MarketplaceService:UserOwnsGamePassAsync(Player.UserId, IDVIP) then
			-- Always indent blocks of code
			local Rank = "VIP"
			
			local Left = Overheads:WaitForChild("Left").Image
			local Right = Overheads:WaitForChild("Right").Image
			if Stats == "God" then
				
				----- THE SCRIPT BELOW WON'T CHANGE THE IMAGE
				Left = "rbxassetid://11260911548" --- This is inside of the overhead
				Right = "rbxassetid://11260917532" ---This is inside of the overhead
				---- EVERYTHING BELOW WORKS NORMALLY
			end
					
			local CloneGui = Overheads:Clone()
			CloneGui.Username.Text = Player.Name
			CloneGui.Rank.Text = Rank
			CloneGui.Parent = Head
			CloneGui.Name = "OverheadGui"
			local Role = "Guest"
			pcall(function()
				Role = Player:GetRoleInGroup(GroupId)
			end)
			CloneGui.Role.Text = Role
		else
			local Left = Overheads.Left.Image
			local Right = Overheads.Right.Image
			-- Always indent blocks of code
			local CloneGui = Overheads:Clone()
			CloneGui.Username.Text = Player.Name
			CloneGui.Name = "OverheadGui"
			CloneGui.Parent = Head
			local Role = "Guest"
			pcall(function()
				Role = Player:GetRoleInGroup(GroupId)
			end)
			CloneGui.Role.Text = Role
		end
	end)
end)

1 answer

✓ Accepted answer

The problem is because the Left and Right variables are set to the property's value but when changed it doesn't update the actual property due to how scripting/coding works.

So instead do this:

local Left = Overheads:WaitForChild("Left")
local Right = Overheads:WaitForChild("Right")
if Stats == "God" then

	----- THE SCRIPT BELOW WON'T CHANGE THE IMAGE
	Left.Image = "rbxassetid://11260911548" --- This is inside of the overhead
	Right.Image = "rbxassetid://11260917532" ---This is inside of the overhead
	---- EVERYTHING BELOW WORKS NORMALLY
end

Full script after fix:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local Overheads = ReplicatedStorage:WaitForChild("OverheadsGui")
local IDVIP = 91491857      ----//VIP ID
local GroupId = 11540689    ----// GROUP ID

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		-- These variables are used regardless of whether the user owns the gamepass or not
		-- so we can define them outside the if statement
		local Humanoid = Character:WaitForChild("Humanoid")
		local Head = Character:WaitForChild("Head")

		local Stats = Player:WaitForChild("leaderstats").Rank.Value

		-- Again, this happens regardless of the if statement
		Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
		if
			MarketplaceService:UserOwnsGamePassAsync(Player.UserId, IDVIP) then
			-- Always indent blocks of code
			local Rank = "VIP"

			local Left = Overheads:WaitForChild("Left")
			local Right = Overheads:WaitForChild("Right")
			if Stats == "God" then

				----- THE SCRIPT BELOW WON'T CHANGE THE IMAGE
				Left.Image = "rbxassetid://11260911548" --- This is inside of the overhead
				Right.Image = "rbxassetid://11260917532" ---This is inside of the overhead
				---- EVERYTHING BELOW WORKS NORMALLY
			end

			local CloneGui = Overheads:Clone()
			CloneGui.Username.Text = Player.Name
			CloneGui.Rank.Text = Rank
			CloneGui.Parent = Head
			CloneGui.Name = "OverheadGui"
			local Role = "Guest"
			pcall(function()
				Role = Player:GetRoleInGroup(GroupId)
			end)
			CloneGui.Role.Text = Role
		else
			local Left = Overheads.Left.Image
			local Right = Overheads.Right.Image
			-- Always indent blocks of code
			local CloneGui = Overheads:Clone()
			CloneGui.Username.Text = Player.Name
			CloneGui.Name = "OverheadGui"
			CloneGui.Parent = Head
			local Role = "Guest"
			pcall(function()
				Role = Player:GetRoleInGroup(GroupId)
			end)
			CloneGui.Role.Text = Role
		end
	end)
end)

1 comment

0

To think that my laziness makes a problem for me, thanks man.

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