Hello, my for loop script isn’t working right.
here is my current script
local plr = game.Players.LocalPlayer
local CloneTemp = script.Parent.Clonetemplate
local inv = plr:WaitForChild("inv")
game.ReplicatedStorage.E.Loadinv.OnClientEvent:Connect(function()
for _, foods in pairs(plr.inv:GetChildren())do
print("Message send")
wait()
local clone = CloneTemp:Clone()
clone.Parent = script.Parent
clone.Visible = true
clone.TextButton.Text = foods.Name
end
end)
game.ReplicatedStorage.E.addtemplate.OnClientEvent:Connect(function(ItemName)
local clonetemplate = CloneTemp:Clone()
clonetemplate.TextButton.Text = ItemName
clonetemplate.Parent = script.Parent
clonetemplate.Visible = true
end)
this script is supose to loop through all the item in the player inventory
it worked for the first time i tested it but the second time for some reason it didn't work
what's wrong with it?
game.ReplicatedStorage.E.Loadinv.OnClientEvent:Connect(function()
for _, foods in pairs(plr.inv:GetChildren())do
print("Message send")
wait()
local clone = CloneTemp:Clone()
clone.Parent = script.Parent
clone.Visible = true
clone.TextButton.Text = foods.Name
end
end)
this one
Does that script print Message send or not now?
What did you expect it to do?
What children did you expect inv to have?
You need to be more specific, we cannot help you if you just say it doesn’t work.
So. The script didn’t print the message and did not loop
the children in the inv is the tool that the player bought
i made a data store for the inv and the script suppose to loop through all tool that are in the player inv and make a template for each of them.