Kropka950
Kropka950

Reputation: 3

Loop help (roblox)

I have a problem with this script:

local plight = script.Parent.Bulb.PointLight
local slight = script.Parent.Bulb.SpotLight
local rotatingPart = script.Parent.Bulb

local reader = script.Parent.Parent["card-reader1a"].reader1a.ProximityPrompt
local c = 0
local cc = 0

local tweenService = game:GetService("TweenService")
local tInfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false)

local function rotating()
    if c == 0 then
        c = 1
        local play1 = tweenService:Create(rotatingPart, tInfo, {CFrame = rotatingPart.CFrame * CFrame.Angles(0, math.rad(120), 0)})
        play1:Play()
        play1.Completed:Connect(rotating)
        c = 0
    end
end

reader.Triggered:Connect(rotating)

I have infinitive loop and I don't know how to stop it. I tried many methods and nothing worked. Can someone help?

Upvotes: 0

Views: 79

Answers (1)

kingerman88
kingerman88

Reputation: 533

Try removing play1.completed:Connect(rotating)

This line of code means that upon the tween's completion fire the rotating function. Effectively causing an infinite loop. Additionally since :Connect() a signal doesn't yield, every time rotating is called, c is set from 1 to 0 almost instantaneously. Which allows all calls to pretty much bypass the debounce.

If you wish to wait until the tween is complete, try using play1.completed:Wait()

Upvotes: 2

Related Questions