I want a script to disable another script for 5s and rerun the script. Can someone please help me do that?

I would like to make a script disable another script when a part is touched, for 5 seconds and rerun the script when re enabled. Can someone please help me on how to do that?

here is my script that I want to disable;

local runservice = game:GetService("RunService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer

local camera = workspace.Camera


local HEIGHT_OFFSET = 8
local CAMERA_DEPTH = 60

local function Camera()
	local character = player.Character
	if character then
		local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
		local RootPosition = humanoidRootPart.Position + Vector3.new(0, HEIGHT_OFFSET, 0)
		local cameraPosition = Vector3.new(-CAMERA_DEPTH ,RootPosition.Y, RootPosition.Z)
		camera.CFrame = CFrame.lookAt(cameraPosition, RootPosition)
	end
end

runservice:BindToRenderStep("SidescrollingCamera", Enum.RenderPriority.Camera.Value + 1, Camera)

basically in that time I want to relocate the player and then make the camera positioning reset so that the camera doesnt just view the player from far away.

1 Like

Make a boolvalue set it to false or true and then check if the thing is false then disable script or else re enable

Im sorry I am not quite that good at coding could you show me what you mean by that?

Insert a new object a boolvalue, then set it for example to true and when a part is touched u set the the boolvalues value to false and then the script checks if the thing is false and then if it is false then run a code u wanna run, in this example disable the script u want to disable

is there a simpler way where I can make the camera able to move forward and backward if the player moves forward or backward just like how it currently follows the player left and right but with no camera rotation?

I have no idea what u mean… have a reference?

This is simply a different script working off the touch of whatever you’re touching in your game to trigger whatever else you’re doing.

local part = script.Parent
local targetScript = part.Parent:WaitForChild("YourTargetScript") 

local function onTouch()
    targetScript.Disabled = true
    task.wait(5)
    targetScript.Disabled = false
end

part.Touched:Connect(onTouch)

You’ll have to add it to your game in the right place or tell the script where the touch part is.
May need a wait buffer before you disable it also. Not sure what all you’re doing. More of a start here.

I’m a little confused what your script is doing, and if you really need to disable it for a second or just opt for something else, but you could try doing something like this:

First script, which is printing hello world every second, but checking if the a boolvalue is true.

while task.wait(1) do
	if script.Parent.Wait.Value == true then
		task.wait(5)
        script.Parent.Wait.Value = false
	else
		print("Hello world!")
	end
end

Second script, which is changing the boolvalue so the other script waits for 5 seconds:

-- detect when player touches a part

script.Parent.Wait.Value = true

-- you could also make this script disable the wait value after five seconds if you want too.