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