Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make this function stop working after 10 seconds?

How do I make it disconnect?

local player = game.Players.LocalPlayer
local hr = Player.Character.HumanoidRootPart 
local mouse = player:GetMouse()

mouse.Move:connect(function()
    hr.CFrame = CFrame.new(hr.Position, mouse.Hit.p*Vector3.new(1,0,1) + hr.Position*Vector3.new(0, 1, 0))
wait(10)
--What do I do to make it disconnect?
end)

3 comments

0

con = mouse.Move... wait(10) con:Disconnect()?

0

script:Destroy() maybe? or script.Disabled = true

0

I already tried disconnect won't work

1 answer

Try this

local player = game.Players.LocalPlayer
local hr = Player.Character.HumanoidRootPart 
local mouse = player:GetMouse()

mouse.Move:connect(function()
    hr.CFrame = CFrame.new(hr.Position, mouse.Hit.p*Vector3.new(1,0,1) + hr.Position*Vector3.new(0, 1, 0))
wait(10)
break
end)

4 comments

0

You capitalized break

0

Also, break doesn't work in functions, only in loops.

0

Ya ;/

0

Yea sorry about that... I didn’t realize. I figured it would work but didn’t relieve at the moment break can’t be used in functions

This discussion is preserved as it was. New answers, comments, and votes are closed.