Some indexing/tool giving issues

Hey, Ive got some shop/inventory logic system where theres buttons for items and a prompt shows up for its name and description and a claim option. Im having this problem where i’m having some indexing issues where it’s giving me all the tools at once.

I really don’t know much a lot about scripting so help is appreciated if i need to change anything
I have all events and tools in Replicated storage

Code on how the buttons are made:

script.Parent.Parent.Enabled = true
local frame = script.Parent
frame.Visible = false
local scrollFrame = frame.ShopScrollFrame

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local tools = ReplicatedStorage:WaitForChild("Tools")
local event = ReplicatedStorage:WaitForChild("SetName")
local event2 = ReplicatedStorage:WaitForChild("Event")

local CloneButton
local ClaimButton

-- index, item, table.....
for i, tool in tools:GetChildren() do
	CloneButton = scrollFrame.PresetButton:Clone()

	CloneButton.Image = tool.TextureId
	CloneButton.ToolName.Text = tool.Name
	CloneButton.Name = tool.Name.."Button"
	CloneButton.Parent = scrollFrame
	CloneButton.Activated:Connect(function()
		event:Fire(tool)
	end)
	
	ClaimButton = script.Parent.CanvasFrame.ToolReviewFrame.ClaimButton
	
	ClaimButton.Activated:Connect(function()
		event2:FireServer(tool)
	end)
end

scrollFrame.PresetButton:Destroy()

Code that handles the description prompt thing:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local event = ReplicatedStorage:WaitForChild("SetName")
local event2 = ReplicatedStorage:WaitForChild("Event")
local tools = ReplicatedStorage:WaitForChild("Tools")

local tweenService = game:GetService("TweenService")
local frame = script.Parent

frame.Position = UDim2.new(1.5, frame.Position.X.Offset, frame.Position.Y.Scale, frame.Position.Y.Offset)

local target = 0.5
local tweenInfo = TweenInfo.new(0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local tween = tweenService:Create(frame, tweenInfo, {Position = UDim2.new(target, frame.Position.X.Offset, frame.Position.Y.Scale, frame.Position.Y.Offset)})

event.Event:Connect(function(tool)
	frame.Visible = true
	tween:Play()

	script.Parent.ToolName.Text = tool.Name
	script.Parent.ToolImage.Image = tool.TextureId
	script.Parent.ToolDescription.Text = tool.ToolTip
end)


Code where it fires “Event” from serverscriptservice

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local tools = ReplicatedStorage:WaitForChild("Tools")
local event = ReplicatedStorage:WaitForChild("Event")

event.OnServerEvent:Connect(function(player, tool)
	local backpack = player.Backpack
	local character = player.Character
	local toolClone = tool:Clone()
	
	if backpack:FindFirstChild(tool.Name) then
		backpack[tool.Name]:Destroy()
	end
	
	if character:FindFirstChild(tool.Name) then
		character[tool.Name]:Destroy()
	end
	
	toolClone.Parent = backpack
end)

Heres some video footage

It might be this. The ClaimButton is the same for every tool in the for loop for the first script. This means that the .Activated event would fire (and thus event2:FireServer(tool)) for every single tool.

You could either keep track of the selected tool to claim, like within the inventory menu, and have a check for the index. Or, you could have a claim button for each tool.

1 Like