Shop Gui messed up

Hello everyone! I’m trying to make a shop for my gun game where you can equip an item when the game starts, for me some of the text doesn’t show up, for example when I buy it it says ‘Bought!’, then it changes to ‘equip’ but, when I press equip it says unequipped, it is suppose to say equipped, any help would be fantastic! (This is similar to Alvin blox’s shop tutorial).

If you want more info reply to me!

Script when buying an item:

buyButton.MouseButton1Click:Connect(function()
local result = game.ReplicatedStorage.PurchaseItem:InvokeServer(selectedItem.Value)
if result == true then
buyButton.BackgroundColor3 = Color3.fromRGB(42,149,42)
buyButton.Text = “Bought!”
wait(0.5)
buyButton.Text = “Equip”
buyButton.BackgroundColor3 = Color3.fromRGB(55,193,55)
elseif result == “NotEnoughCredits” then
buyButton.BackgroundColor3 = Color3.fromRGB(204,31,31)
buyButton.Text = “Not Enough Credits”
wait(0.5)
buyButton.Text = “Buy”
buyButton.BackgroundColor3 = Color3.fromRGB(55,193,55)
elseif result == “Equipped” then
equippedItem.Value = selectedItem.Value
buyButton.BackgroundColor3 = Color3.fromRGB(42,149,42)
buyButton.Text = “Equipped!”
wait(0.5)
buyButton.Text = “Unequip”
buyButton.BackgroundColor3 = Color3.fromRGB(55,193,55)
elseif result == “Unequipped” then
equippedItem.Value = “”
buyButton.BackgroundColor3 = Color3.fromRGB(42,149,42)
buyButton.Text = “Unequipped!”
wait(0.5)
buyButton.Text = “Equip”
buyButton.BackgroundColor3 = Color3.fromRGB(55,193,55)
end
end)

Server script:


game.ReplicatedStorage:WaitForChild("GetTools").OnServerInvoke = function(player)
	local items = {}
	
	for _, object in pairs(game.ServerStorage:WaitForChild("Items"):GetChildren()) do
		local itemProperties = {object.Name,object.Price.Value}
		table.insert(items,itemProperties)
	end
	
	return items
end

game.ReplicatedStorage:WaitForChild("ItemCheck").OnServerInvoke = function(player,itemName)
	if game.ServerStorage.PlayerData:FindFirstChild(player.Name).Inventory:FindFirstChild(itemName) then
		return true
	else
		return false
	end
end

game.ReplicatedStorage:WaitForChild("PurchaseItem").OnServerInvoke = function(player,itemName)
	local Credits = player.leaderstats.Credits
	local item = game.ServerStorage.Items:FindFirstChild(itemName)
	
	if item then
		--Item exists
		if game.ServerStorage.PlayerData[player.Name].Inventory:FindFirstChild(itemName) then
			if game.ServerStorage.PlayerData[player.Name].Equipped.Value == itemName then
				-- Currency Unequipped
				game.ServerStorage.PlayerData[player.Name].Equipped.Value = itemName
				return "Equipped"
			else
				game.ServerStorage.PlayerData[player.Name].Equipped.Value = ""
				return "Unequipped"
			end 
		end
		
		if Credits.Value >= item.Price.Value then
			Credits.Value = Credits.Value - item.Price.Value
			
			local itemValue = Instance.new("ObjectValue")
			itemValue.Name = itemName
			itemValue.Parent = game.ServerStorage.PlayerData[player.Name].Inventory
			
			return true
		else
			
			return "NotEnoughCredits"
		end
		
	else
		return "NoItem"
	end
end

Hey again :slight_smile:

In your server script, the logic for equipping and unequipping seems to be reversed:

if game.ServerStorage.PlayerData[player.Name].Equipped.Value == itemName then
    game.ServerStorage.PlayerData[player.Name].Equipped.Value = itemName
    return "Equipped"
else
    game.ServerStorage.PlayerData[player.Name].Equipped.Value = ""
    return "Unequipped"
end 

If the player’s equipped item is the same as the item they’re trying to equip, you’re setting their equipped item to that item again (which is redundant) and returning “Equipped”. Otherwise, you’re unequipping the item. This logic seems backward. You probably want to equip the item if it’s not already equipped and unequip it if it is.

if game.ServerStorage.PlayerData[player.Name].Equipped.Value == itemName then
    game.ServerStorage.PlayerData[player.Name].Equipped.Value = ""
    return "Unequipped"
else
    game.ServerStorage.PlayerData[player.Name].Equipped.Value = itemName
    return "Equipped"
end 

So how would it look like in my server script? not the best scripter, a bit behind.

And I will elaborate on my issue,

So the button when you press on a certain item, it says buy, when you buy it it says ‘Bought!’ then it changes into ‘Equip’, when you press equip, it is suppose to say equipped and the item CFrame image is shown on the bottom left corner of you screen that you equipped it, then it goes back to ‘unequip’, when you press unequip, it then says ‘unequipped’, but this is not the case.

When I press equip, it says ‘unequip’ then back to ‘equip’ and the image is not shown on the bottom left corner, I will show you a video on what is the issue.

robloxapp-20231006-1758490.wmv (630.4 KB)