Im trying to code a spleef but All of part's are same name and I dont know how to code like that and If I do loop like i,v in pairs it lags really badly and I need help :C (laggy means that it doesnt debounce)
script:
--By enes223 local touchedParts = {} while wait() do spawn(function() for _,v in pairs(script.Parent:GetChildren()) do if not touchedParts[v] then touchedParts[v] = true v.Touched:connect(function() for i = 0.1,1,0.1 do v.Transparency = i wait(0.01) end v.CanCollide = false end) end end end) end
You can create click events for each of your bricks by doing the following: You only have to run this at the beginning of your game because you only need one click event for each block.
What the script does is gets the blocks in a group and puts them into a table. (I think we went over tables a couple weeks ago, but if you need that explained again, let me know)
It loops through the blocks table and then creates a touch event for each block. Your logic should be where the comment is.
blocks = game.Workspace.BlocksGroup:GetChildren() for i, v in ipairs(blocks)do v.Touched:Connect(function() --do the logic for each touch event here end) end