I'm trying to add a while true do or repeat until loop inside this function but i also want to stop it in 2 seconds i know you can do somthing similar to a function for example
touch = part.Touched:Connect(function() print "got it" end) wait (2) touch:Disconnect()
im trying to go for something like this but with a loop it's hard ;/
here's my attempt
game.ReplicatedStorage:WaitForChild("shocky").OnServerEvent:Connect(function(plr) local s = script.s:Clone() script.shock:Play() s.Parent = plr.Character.Head local n = 0 repeat print("doing code") wait (1) n = n + 1 until n == 2 wait (2) script.shock:Stop() s:Destroy() end)
but it wont work because the wait(1) is gonna destroy the wait() loop
local n = 0 while n < 2 do print("doing code") wait (1) n = n + 1 end