So on the client I have a script that has a function and then inside of that function has another function. It doesn’t seem to matter if I have the function inside the other or not, but for some reason when a button I have is clicked, the function fires multiple times. Here’s the small section of script where that happens:
I would attach a video but it won’t let me. So as you can kind of see, I have a line that prints out when the function takes place and the function happens multiple times and increases as I use the function. But, when I use the function the first time, it only calls once, so the function doesn’t actually get messed up at all.
Here’s the InteractItem function:
local function interactItem(itemName)
local data = interactItemFunc:InvokeServer(itemName)
if data then
playerData = data
updateItems()
end
end
I’m not sure if this is a common issue, or if there’s any way to fix it without seeing a lot of my script, but if there isn’t I can show more of my script.
Heres a hacky workaround. Let me know if it doesn’t work.
local CanShop = false
newButton.Activated:Connect(function()
CanShop = not CanShop
end)
buyButton.Activated:Connect(function()
if CanShop == true then
interactItem(tower.Name)
print("Interacted")
end
end)
If the only purpose of newButton is to reveal or unlock the buyButton, then you can use a boolean variable instead of a nested function to unlock the buyButton via the newButton clicking.
Here’s what the code could look like:
local buyButtonCheck = false
newButton.Activated:Connect(function()
buyButtonCheck = true
end)
buyButton.Activated:Connect(function()
if buyButtonCheck then
interactItem(tower.Name)
print("Interacted")
end
end)
Sorry for the late response, but I’m not exactly sure what you’re asking, so I’m gonna explain it a little bit better than before so it’s easier to understand what’s happening
A have a function updateItems() which is used and has a for i, loop in it. Inside of that for i, loop, there is a newButton.Activated:Connect(function() with the buyButton.Activated:Connect(function() inside of it. The buyButton.Activated:Connect(function() calls another function called interactItem(tower.Name). In a serverscript I have a line that calls the interactItem function which is: