I’m trying to set a image and label to the decal and text when clicked on a button of an item, but it is not working.
local Starterpack = game:GetService("StarterPack")
local startergui = game:GetService("StarterGui")
local serverstorage = game:GetService("ServerStorage")
local goldenknife = serverstorage:WaitForChild("GoldenKnife")
local inventoryframe = startergui.InventoryGui.InventoryFrame
local weaponimage = inventoryframe.ItemsFrame.WeaponFrame:WaitForChild("WeaponImage")
local weaponname = inventoryframe.ItemsFrame.WeaponFrame:WaitForChild("WeaponName")
local goldenname = "Golden Knife"
local goldendecal = "rbxassetid://16584185412"
local equippedframe = inventoryframe.KnifeFrame
local equippedimage = equippedframe.WeaponImage
local equippedlabel = equippedframe.WeaponLabel
if goldenknife then
weaponname.Text = goldenname
weaponimage.Image = goldendecal
end
equippedlabel.Text = "???"
---here is my main issue
weaponname.MouseButton1Click:Connect(function(click)
equippedimage = goldendecal
equippedlabel = goldenname
end)
Can you please post any errors that may be appearing inside the Output View > Output
Also, is this being handled inside a LocalScript? User input must be handled via a LocalScript, LocalScripts are for client only, the server doesn’t know what the user is clicking on.
You will then have to port the code to work with the local player.
Example:
This >
local inventoryframe = startergui.InventoryGui.InventoryFrame
Would turn into this >
local players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local inventoryframe = localPlayer.PlayerGui.InventoryGui.InventoryFrame
The StarterGui service is, to put it simply, a storage vessel for all the UI that needs to be replicated to each individual client when they load in. When the UI inside of StarterGui is replicated it is placed into the local player’s PlayerGui.
In order to make any changes to the client’s UI you need to access it via PlayerGui otherwise you just wouldn’t be making any changes!
You need to change the actual image property and text property of equippedimage and equipped label.
Currently equippedimage and equippedlabel are variables that contain instances.
Change
@tannnxr
This is my only error, but it doesn’t make sense. I’ve changed it to a LocalScript and here’s my updated code.
–error value of type string cannot be converted to a number
-code
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local Starterpack = game:GetService("StarterPack")
local playergui = localPlayer.PlayerGui
local serverstorage = game:GetService("ServerStorage")
local goldenknife = serverstorage:WaitForChild("GoldenKnife")
local inventoryframe = localPlayer.PlayerGui.InventoryGui.InventoryFrame
local weaponimage = inventoryframe.ItemsFrame.WeaponFrame:WaitForChild("WeaponImage")
local weaponname = inventoryframe.ItemsFrame.WeaponFrame:WaitForChild("WeaponName")
local goldenname = "Golden Knife"
local goldendecal = "rbxassetid://16584185412"
local equippedframe = inventoryframe.KnifeFrame
local equippedimage = equippedframe.WeaponImage
local equippedlabel = equippedframe.WeaponLabel
if goldenknife then
weaponname.Text = goldenname
weaponimage.Image = goldendecal
end
equippedlabel.Text = "???"
weaponname.MouseButton1Click:Connect(function()
equippedimage.Image = goldendecal
equippedlabel.Text = goldenname
end)