Hello Scripters!
So for context, I have group of tiles that the player is able to step on. Any tile that they step on will disappear and then regenerate after a certain amount of time.
I’ve been using CollectionService collaboritively with a Touched function. Each tile has a tag named “Spleef.”
The issue isn’t that it’s broken – because it’s not. The issue is that there is LOTS of lag when the player is stepping on the tiles. I can’t seem to figure out how to minimize the lag spikes. (Especially if multiple players are going to step on the tile.)
for _, tile in CollectionService:GetTagged("Spleef") do
local debounce = false
tile.Touched:connect(function(hit)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("Humanoid").Health > 0 then
if debounce == false then
debounce = true
print("Tile Disapearing")
wait(DV.Value)
print("Tile Appearing")
wait(0.60)
debounce = false
end
end
end)
end
The prints are just a placeholder for the actual action that happens. So in prints, it may not lag – but with the actual Tweening of tiles, it lags quite a lot.
Any ideas on how I can make this script more efficient? Is it smart to have a Touched event in a for loop?