Pretty straight forward question
This is a LOCAL script
local itemIcons = {
["StarterWeapon"] = "rbxassetid://7306739276",
["Weapon2"] = "rbxassetid://7306744538"
}
while true do wait()
local itemEquipped = plr:WaitForChild("EquippedItem").Value
itemImage.Image = itemIcons[itemEquipped]
end
Thanks in advance!
Are you sure that it’s not just the Value equaling to nil
when you first start it up…?
My assumption is that when a Player equips an item, that EquippedItem
StringValue gets changed to the current item equipped on your Character?
Yeah, but it’s automatically set to “StarterSword”
game.Players.PlayerAdded:Connect(function(plr)
local equippedItem = Instance.new("StringValue",plr)
equippedItem.Name = "EquippedItem"
equippedItem.Value = "StarterSword"
Couldn’t you just check every time the StringValue changes using a Changed
Event instead of a while true do
loop? It’d be way more simpler that way to handle it
local Player = game.Players.LocalPlayer
local EquippedItem = Player:WaitForChild("EquippedItem")
local itemIcons = {
["StarterSword"] = "rbxassetid://7306739276",
["Weapon2"] = "rbxassetid://7306744538"
}
local function ChangeImage(NewValue)
itemImage.Image = itemIcons[NewValue]
end
EquippedItem.Changed:Connect(ChangeImage)
ChangeImage(EquippedItem.Value)
I also believe that you’re trying to check for 2 different things, cause StarterSword
& StarterWeapon
are both different strings
1 Like
Ahh thank you, haha made a typo. I should’ve changed StarterWeapon to StarterSword… Thanks!!