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

Why is my cooldown script no longer working anymore?

So I've created a testing game where I test various magics for use in a game I'm thinking of creating, and I have recently created a new magic. Everything is fine, and works as it should, however for some reason, today, one move's cooldown only works in Studio - The Time Stop (Ultimate move). The cooldown used to work previously, but today I was fixing some bugs associated with this move and then the cooldown script stopped working. No errors, no warnings, no nothing.

This is the localscript code:

local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid

local debounce = false

mouse.KeyDown:connect(function(key)
	if key == "x" and not debounce then
		debounce = true
		game.ReplicatedStorage.TimestopEvent:FireServer()
		wait(60)
		debounce = false
	end
end)

And this is the server script code:

local b = game.Lighting.Blur
local c = game.Workspace.Camera
local e = game.Workspace.TSAura

game.ReplicatedStorage.TimestopEvent.OnServerEvent:Connect(function(player)
	print("Time Stop success!")
	game.Workspace["Time Stop Audio"]:Play()
	wait(1.5)
	b.Size = 2
	game.Lighting.TimeOfDay = '14:00:00'
	wait(0.05)
	game.Lighting.TimeOfDay = '13:50:00'
	wait(0.05)
	game.Lighting.TimeOfDay = '13:00:00'
	wait(0.05)
	b.Size = 3
	game.Lighting.TimeOfDay = '13:50:00'
	wait(0.05)
	game.Lighting.TimeOfDay = '12:00:00'
	wait(0.05)
	game.Lighting.TimeOfDay = '11:50:00'
	wait(0.05)
	b.Size = 5
	game.Lighting.TimeOfDay = '11:00:00'
	wait(0.05)
	game.Lighting.TimeOfDay = '10:50:00'
	wait(0.05)
	b.Size = 7
	game.Lighting.TimeOfDay = '10:00:00'
	wait(0.05)
	game.Lighting.TimeOfDay = '9:50:00'
	wait(0.05)
	game.Lighting.TimeOfDay = '9:00:00'
	wait(0.05)
	game.Lighting.TimeOfDay = '8:50:00'
	wait(0.05)
	game.Lighting.TimeOfDay = '8:00:00'
	wait(0.05)
	b.Size = 10
	game.Lighting.ColorCorrection.Enabled = true
	game.Lighting.TimeOfDay = '7:50:00'
	wait(0.05)
	e.Position = Vector3.new(player.Character.HumanoidRootPart.Position.X , player.Character.HumanoidRootPart.Position.Y + 2, player.Character.HumanoidRootPart.Position.Z)
	game.Workspace.TSAura.Script.Disabled = false
	game.Lighting.TimeOfDay = '7:00:00'
	wait(0.05)
	game.Lighting.TimeOfDay = '6:50:00'
	wait(0.05)
	game.Lighting.TimeOfDay = '6:00:00'
	wait(0.05)
	game.Lighting.TimeOfDay = '5:50:00'
	wait(0.05)
	b.Size = 24
	game.Lighting.TimeOfDay = '5:00:00'
	wait(0.05)
	b.Size = 22
	game.Lighting.TimeOfDay = '4:50:00'
	wait(0.05)
	b.Size = 20
	game.Lighting.TimeOfDay = '4:00:00'
	wait(0.05)
	b.Size = 18
	game.Lighting.Blur2.Enabled = true
	game.Lighting.TimeOfDay = '3:50:00'
	wait(0.05)
	b.Size = 16
	game.Lighting.TimeOfDay = '3:00:00'
	wait(0.05)
	game.Lighting.TimeOfDay = '2:50:00'
	wait(0.05)
	game.Lighting.TimeOfDay = '2:00:00'
	wait(0.05)
	game.Lighting.TimeOfDay = '1:50:00'
	wait(0.05)
	game.Lighting.TimeOfDay = '1:00:00'
	wait(0.05)
	game.Lighting.TimeOfDay = '0:50:00'
	wait(0.05)
	b.Size = 0
	game.Lighting.TimeOfDay = '0:00:00'
	wait(1.24)
	game.Lighting.Blur2.Enabled = false
	b.Size = 5
	game.Workspace.TSAura.Script.Disabled = true
	e.Transparency = 1
	game.Workspace.NoMoreTS.Disabled = false
	for i,v in next,workspace:GetDescendants() do if v:IsA"Part" and v.Parent:findFirstChild("Humanoid") then
		v.Anchored = true
		for i,s in next,workspace:GetDescendants() do if s:IsA"Script" and s.Parent:FindFirstChild("Humanoid") then
			s.Disabled = true
			for i,p in next,game.Players:GetDescendants() do if p:IsA"LocalScript" then
				p.Disabled = true
			end end
		end end
	end
end
end)

This is the main script that later triggers other scripts, which I will not put here as I do not believe it is very relevant to my issue.

When I press "X", the time stop itself works as planned. I'm happy with that. What I'm not happy with is the fact that although I set the debounce, or cooldown, to 60 seconds (1 minute), it only works in Studio. What I mean is if I published this to a game, I can spam "X" to stop time whenever I want, even during the time stop itself. I've searched this issue up on Google and tried some methods but they only worked on Studio - none of them worked in the real game. It used to work before, same scripts, but for some reason it just suddenly stopped working. The console logs no errors for the time stop script, so I don't know what's wrong.

Any help?

2 comments

0

because roblox updated something i don't know why they change it! normal leaderstats is not working not.

0

That's weird, although the other attacks' cooldown scripts work perfectly fine, I'm not sure what's with this script that just screws everything up.. Maybe they'll fix it soon, I don't know.

1 answer

Never mind, I fixed it. The mistake was that I made the time stop script disable all player local scripts (because they trigger the remote events that fired magic attacks), including the time stopper. To make the time-stopper move in stopped time, I also had a script that unanchored the time-stopper's character parts and re-enabled the local scripts so that they can attack during stopped time. This caused the Debounce (or cooldown) to reset to 0, allowing the time-stopper to spam X to time stop.

I fixed this by changing the server script to include and p.Name ~= "TimeStopKeybindScript", because that was the name of the localscript that starts the time stop, so the full line for the time stop would be:

for i,v in next,workspace:GetDescendants() do if v:IsA"Part" and v.Parent:findFirstChild("Humanoid") then
		v.Anchored = true
		for i,s in next,workspace:GetDescendants() do if s:IsA"Script" and s.Parent:FindFirstChild("Humanoid") then
			s.Disabled = true
			for i,p in next,game.Players:GetDescendants() do if p:IsA"LocalScript" and p.Name ~= "TimeStopKeybindScript" then
				p.Disabled = true
			end end
		end end
	end
end
end)

It was a very simple fix, sorry for any inconveniences.

2 comments

0

In case some of you are confused about what these lines of code does, it basically makes the "time stop" a time stop by anchoring all player and NPC parts so that they cannot move. It also disables all NPC scripts so that they cannot attack, and lastly, it also disables all player localscripts (located in the backpack) that are NOT named "TimeStopKeybindScript".

0

The mistake was that I didn't add the 'and p.Name ~= "TimeStopKeybindScript"', which means that this script would've been affected by the initial time stop. Another script re-enables this script, resetting the cooldown. By adding the fix, the localscript triggering the time stop is immune to the effects of the time stop, leaving the cooldown untouched.

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