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

Wait Command Cooldown Time Fluxuates while using UserInputService and only UserInputService?

Script One: Mobile Controls (In a Gui Button.) (Local Script) (Works Fine)

local Player = game.Players.LocalPlayer

local Character = Player.Character or Player.CharacterAdded:Wait()

local debounce = false

script.Parent.MouseButton1Click:Connect(function()
	if Character.HumanoidRootPart.Anchored == false then
		if debounce == false then

			debounce = true

			if Player.leaderstats.Nature.Value == "Fire" then
				game.ReplicatedStorage.FireWall:FireServer()
			elseif Player.leaderstats.Nature.Value == "Grass" then
				game.ReplicatedStorage.GWall2:FireServer()
			elseif Player.leaderstats.Nature.Value == "Water" then
			game.ReplicatedStorage.WaWalk2:FireServer()
			end
			wait(9)
			debounce = false
		end
		end
end)

Script Two: UserInputService (In StarterPack) (Is A Local Script)

local UserInputService = game:GetService("UserInputService")

local Player = game.Players.LocalPlayer

local Character = Player.Character or Player.CharacterAdded:Wait()

local debounce = false


UserInputService.InputBegan:Connect(function(Input, isTyping)
	if not isTyping then
		if Character.HumanoidRootPart.Anchored == false then
		if not debounce then

			debounce = true

			if Input.KeyCode == Enum.KeyCode.E then
				if Player.leaderstats.Nature.Value == "Fire" then
					game.ReplicatedStorage.FireWall:FireServer()
				elseif Player.leaderstats.Nature.Value == "Grass" then
					game.ReplicatedStorage.GWall2:FireServer()
				elseif Player.leaderstats.Nature.Value == "Water" then
					game.ReplicatedStorage.WaWalk2:FireServer()
				end
			end
			wait(9)
				debounce = false
				end
		end
	end
end)

Script One Works totally fine and the cooldowns are on point every time, but with script 2, Cooldowns can take up to a whole Minute. I've tried moving the ends and its the same problem, does anyone know why this is happening?

1 answer

✓ Accepted answer

A whole minute? That's weird. wait(n) is known for being slightly inaccurate (often off by a hundredth or even a tenth of a second, but a whole ~50 seconds off?) That is indeed weird.

How many times have you tested these out in those different locations? This is probably not the solution, but I suggest using StarterPlayerScripts or StarterCharacterScripts over StarterPack (which is meant for tools).

I can't help but think something else is going wrong, since wait never slows down that much unless you have some INTENSE lag going on. Maybe you could try this script in an empty place with no other interruptions to narrow down the cause? Or perhaps you could try to create a cooldown system using RunService.Hearbeat or some other event. Otherwise, I'm stumped. Sorry that I don't have more for you.

1 comment

0

This actually worked

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