Help With equip system and buy system

  1. What do you want to achieve? Solution to fix my buy button and equi[ function

  2. What is the issue? When i click the buy button, the item is not being bought even though i have enough currency for that

  3. What solutions have you tried so far? I tried using a remote event to help me but that still didnt work

--my buy button script

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	local item = script.Parent.Parent.name.Text
	
	if script.Parent.Parent.status.Text == "Buy" then
		game.ReplicatedStorage.Remotes.BoughtTool:FireServer(item)
	elseif script.Parent.Parent.status.Text == "Equip" then
		game.ReplicatedStorage.Remotes.EquipTool:FireServer(item)
	end
	
end)


game.ReplicatedStorage.Remotes.BoughtTool.OnClientEvent:Connect(function(item)
	
	game.ReplicatedStorage.Remotes.EquipTool:FireServer(item)
	print("Recieves")
	local number = 0
	for i,v in pairs(script.Parent.Parent.ScrollingFrame:GetChildren()) do
		if v:FindFirstChild("ToolName") then
			if v.name.Value == item then
				number = tonumber(v.Name)
			end
		end
	end
	
	if number ~=nil then
		for i,v in pairs(script.Parent.Parent.ScrollingFrame:GetChildren()) do
			if v:FindFirstChild("ToolName") then
				local thenumber = tonumber(v.Name)
				if thenumber <=number or thenumber == number +1 then
					v.Tool_img.ImageColor3 = Color3.fromRGB(255,255,255)
				end
			end
		end
	end
	
	for i, v in pairs(script.Parent.Parent.Parent.tools_frame.ScrollingFrame:GetChildren()) do
		if v:FindFirstChild("ToolName") then
			if v.tool_img.Image == script.Parent.Parent.Parent.ImageOftool.Image then
				if v.tool_img.ImageColor3 == Color3.fromRGB(255,255,255) then
					script.Parent.Parent.tool_img.ImageColor3 = Color3.fromRGB(255,255,255)
				end
			end
		end
	end
	

end)

game.ReplicatedStorage.Remotes.EquipTool.OnClientEvent:Connect(function(item)
	if script.Parent.Parent.name.Text == item then
		script.Parent.Text = "Equipped"
	end
	
end)

--My Equip tool script

game.ReplicatedStorage.Remotes.EquipTool.OnServerEvent:Connect(function(player, item)
	if player.OwnedItems:FindFirstChild(item) then
		for i, ifthere in pairs(player.Backpack:GetChildren()) do
			ifthere:Destroy()
		end
		for i, ifthere in pairs(player.Character:GetChildren()) do
			if ifthere:IsA("Tool") then
				if game.ServerStorage.Tools:FindFirstChild(ifthere.Name) then
					ifthere:Destroy()
				end
			end
		end

		local clone = game.ServerStorage.Tools:FindFirstChild(item):Clone()
		clone.ItemNumber:Destroy()
		clone.Cost:Destroy()
		clone.Parent = player.Backpack
		player.Equipped.Value = item
		game.ReplicatedStorage.Remotes.EquipTool:FireClient(player, item)
	end
	end)

help me ASAP please and thank you.

1 Like

Do you get any errors in console though?

1 Like

No errors in the output and no warnings too. There is no clue why this happend

1 Like
game.ReplicatedStorage.Remotes.BoughtTool.OnClientEvent:Connect(function(item)

Is there a 3rd script? I don’t see in either script where the BoughtTool remote is used to fire the client.

oops sorry i forgot to send the 3rd script here:


local ds = game:GetService("DataStoreService")
local dsstore = ds:GetDataStore("Toolsystem")

game.ReplicatedStorage.Remotes.BuyAll.OnServerEvent:Connect(function(plr)
	local highest = 1
	for i,v in pairs(plr.OwnedItems:GetChildren()) do
		local tool = game.ServerStorage.Tools:FindFirstChild(v.Name)
		if tool.ItemNumber.Value > highest then
			highest = tool.ItemNumber.Value
		end
	end
	print("cool")
	local nextnumber = highest +1
	local done = false
	repeat
		for i, v in pairs(game.ServerStorage.Tools:GetChildren()) do
			if v:FindFirstChild("ItemNumber") then
				if v.ItemNumber.Value == nextnumber  then
					if plr.leaderstats.Coins.Value >= v.Cost.Value then
						local bool = Instance.new("BoolValue")
						bool.Name = v.Name
						bool.Parent = plr.OwnedItems
						nextnumber = nextnumber +1
					else
						done = true
						
					end
				else
					if game.ReplicatedStorage.TotalTools.Value < nextnumber  then
						done = true
						
					end
				end
			end
		end
	until done == true
	local purchased = {}
	if nextnumber-1>highest then
		for i , name in pairs(plr.OwnedItems:GetChildren()) do
			table.insert(purchased , name.Name)
		end
		dsstore:SetAsync(plr.UserId, purchased)
		print("Doing save lol")
	end
	print("YES")
	local item
	for i,v in pairs(game.ServerStorage.Tools:GetChildren()) do
		if v.ItemNumber.Value == nextnumber-1 then
			item = v.Name
		end
	end
	game.ReplicatedStorage.Remotes.BoughtTool:FireClient(plr , item)
end)

also in the first script too:

game.ReplicatedStorage.Remotes.BoughtTool:FireServer(item)

@Limited_Unique

but this script works idk why lol

If you can try and isolate the issue with print commands (see if prints aren’t working in certain areas of code) that’d be very useful.

1 Like

ok i will and tell where there is problem :smiley:

As someone said if you could use print lines that would be great. If there are no errors than something else is the problem.

1 Like

@Limited_Unique , @oSudden i put print in all lines and from here it didnt work (the buy button script)

if script.Parent.Parent.status.Text == "Buy" then
		print("D")
		game.ReplicatedStorage.Remotes.BoughtTool:FireServer(item)
		print("E")
	elseif script.Parent.Parent.status.Text == "Equip" then
		print("F")
		game.ReplicatedStorage.Remotes.EquipTool:FireServer(item)
		print("G")
	end
	
end)


game.ReplicatedStorage.Remotes.BoughtTool.OnClientEvent:Connect(function(item)
	print("H")
	game.ReplicatedStorage.Remotes.EquipTool:FireServer(item)
	print("Recieves")
	local number = 0
	print("I")
	for i,v in pairs(script.Parent.Parent.ScrollingFrame:GetChildren()) do
		print("J")
		if v:FindFirstChild("ToolName") then
			print("K")
			if v.name.Value == item then
				print("L")
				number = tonumber(v.Name)
				print("M")
			end
		end
	end
	
	if number ~=nil then
		print("N")
		for i,v in pairs(script.Parent.Parent.ScrollingFrame:GetChildren()) do
			print("O")
			if v:FindFirstChild("ToolName") then
				print("P")
				local thenumber = tonumber(v.Name)
				print("Q")
				if thenumber <=number or thenumber == number +1 then
					print("R")
					v.Tool_img.ImageColor3 = Color3.fromRGB(255,255,255)
					print("S")
				end
			end
		end
	end
	
	for i, v in pairs(script.Parent.Parent.Parent.tools_frame.ScrollingFrame:GetChildren()) do
		print("T")
		if v:FindFirstChild("ToolName") then
			print("U")
			if v.tool_img.Image == script.Parent.Parent.Parent.ImageOftool.Image then
				print("V")
				if v.tool_img.ImageColor3 == Color3.fromRGB(255,255,255) then
					print("W")
					script.Parent.Parent.tool_img.ImageColor3 = Color3.fromRGB(255,255,255)
					print("X")
				end
			end
		end
	end
	

end)

game.ReplicatedStorage.Remotes.EquipTool.OnClientEvent:Connect(function(item)
	print("Y")
	if script.Parent.Parent.name.Text == item then
		script.Parent.Text = "Equipped"
		print("Z")
	end
	
end)

and nothing in equip script is getting printed ;-;

game.ReplicatedStorage.Remotes.EquipTool.OnServerEvent:Connect(function(player, item)
	print("AA")
	if player.OwnedItems:FindFirstChild(item) then
		print("BB")
		for i, ifthere in pairs(player.Backpack:GetChildren()) do
			print("CC")
			ifthere:Destroy()
			print("DD")
		end
		for i, ifthere in pairs(player.Character:GetChildren()) do
			print("EE")
			if ifthere:IsA("Tool") then
				print("FF")
				if game.ServerStorage.Tools:FindFirstChild(ifthere.Name) then
					print("GG")
					ifthere:Destroy()
					print("HH")
				end
			end
		end

		local clone = game.ServerStorage.Tools:FindFirstChild(item):Clone()
		print("II")
		clone.ItemNumber:Destroy()
		print("JJ")
		clone.Cost:Destroy()
		print("HH")
		clone.Parent = player.Backpack
		print("II")
		player.Equipped.Value = item
		print("JJ")
		game.ReplicatedStorage.Remotes.EquipTool:FireClient(player, item)
		print("KK")
	end
	end)

That means that you’ve coded it wrong or designed the UI wrong.

I recommend starting from scratch with the UI because if it prints nothing that means that your code isn’t being used.

1 Like

Ok. Thanks, I will let you know if there are more errors.

hey also i cant open my roblox studio. Is that have to do with the main servers crashing?

Yep. It is indeed due to the servers crashing.

oh ok thanks. i think i cant use studio today ;(