So, this is quite a difficult problem to try and explain but I will try my best, aha.
What I want my script to do is to loop through a model, and find out which TextButton was clicked and then turn that TextButton.Name into a variable. (This is all done through a local script as it is doing work with GUI's). I then want it to send the variable name through a RemoteEvent/RemoteFunction (not entirely sure on which one to use) and for it to take the variable name and then to clone a tool with the same name and put it into the player's backpack for all players to see. This is the code that I was previously using before I found out I even had to use RemoteEvents/functions, (stupid I know), but now I've found out it is needed to be changed.
Code:
local frame = script.Parent.Frame
local tool = game.ReplicatedStorage.Crisps
for i,v in pairs(frame:GetChildren()) do
game.Workspace.Bowl.ClickDetector.MouseClick:Connect(function(player)
frame:TweenPosition(UDim2.new(0.125, 0,0.141, 0))
v.MouseButton1Click:Connect(function()
local flavour = v
for i,v in pairs(tool:GetChildren()) do
if v.Name == flavour.Name then
local added = script.Parent.added
v:Clone().Parent = player.Backpack
added.Text = "Added one packet of "..v.Name
added:TweenPosition(UDim2.new(0.03, 0,0.032, 0))
wait(2)
added:TweenPosition(UDim2.new(0.03, 0,-0.2, 0))
frame:TweenPosition(UDim2.new(0.113, 0,1.05, 0))
end
end
end)
end)
end
I hope you understand what problem I was trying to solve.I also don't want corrections on my code, I want to actually gain something from the advice so I can use it for the future as there is clearly a problem in my learning, please don't change my code around if it is not needed just now, I just want it to function correctly.
