Here is the code:
function itemPurchasingManager(tycoonBaseplate, serverBaseplate, tycoon)
for i,v in pairs(tycoonBaseplate.Buttons:GetChildren()) do
v.Head.Touched:Connect(function(hit)
print("Button was touched")
-- there are more if statements and things here but the print above only fires once or twice so I know that they are not the problem
Here is when I call the function:
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
local plrName = plr.Name
local plrInfo = game.ServerStorage:FindFirstChild(plrName):WaitForChild("PlayerInfo")
local specialKey = "User_"..plr.UserId
local tycoon = script.Parent.Parent.Parent.Parent
local tycoonName = tycoon.Name
local savedPurchasedItemsTable
local buildLevel = plrInfo.BuildLevel.Value
local serverTycoon = game.ServerStorage:FindFirstChild("Model"..tycoon.Color.Value.."Tycoon")
local baseplate = findBaseplate(buildLevel, serverTycoon)
local baseplateName = baseplate.Name
local tycoonBaseplate = tycoon:FindFirstChild("Baseplates"):WaitForChild(baseplateName)
local serverBaseplate = serverTycoon:WaitForChild(baseplateName)
if not plrInfo.OwnsTycoon.Value then
if not tycoon.IsOwned.Value then
if hit.Parent.Humanoid.Health > 0 then
tycoon.IsOwned.Value = true
tycoon.Owner.Value = plrName
plrInfo.OwnedTycoon.Value = tycoon.Name
plrInfo.OwnsTycoon.Value = true
local success, message = pcall(function()
print("Hello")
savedPurchasedItemsTable = purchasedItemsDataStore:GetAsync(specialKey) or nil
print("Hello2")
end)
if success then
print("Player Data Loaded Successfully")
local copy = baseplate.Essentials:Clone()
copy.Parent = tycoon.Baseplates:FindFirstChild(baseplateName)
if savedPurchasedItemsTable then
print("This Player Has Saved Items")
createButtonsAndItems(serverBaseplate, tycoonBaseplate, savedPurchasedItemsTable)
wait(.5)
itemPurchasingManager(tycoonBaseplate, serverBaseplate, tycoon)
else
print("This Player Has No Purchased Items In This Baseplate")
createButtonsAndItems(serverBaseplate, tycoonBaseplate, savedPurchasedItemsTable)
wait(.5)
itemPurchasingManager(tycoonBaseplate, serverBaseplate, tycoon)
end
script.Parent.Transparency = 1
script.Parent.CanCollide = false
else
print("Player Data Failed To Load Successfully")
plr.CanSave = false
plr:Kick("Your Data Failed To Load Successfully Please Rejoin")
end
end
end
end
end
end)
can anyone please help me. (by the way this is not a free model I wrote it myself) if there are any problems in the code that are irrelevant to the problem please ignore them. I just want to fix this one bug for now. This is all one script. If that is a problem please tell me.

2 comments
Does it have anything to do with the for loop? Or am I using Touched incorrectly(I dont think so)? And why does it work a few times but not any more?
it says solved because I took another approach not because it was solved in any way shape or form