When i try to run my TimeStop script, it doesnt work as intended to work.
I havent changed anything to the script, and it worked perfectly fine yesterday. But ever since today it hasnt worked and im not sure whats wrong with the script since the output isnt showing any errors.
Heres the output
Heres the code im using
Code
Client
local UIS = game:GetService("UserInputService")
local lighting = game.Lighting
local bool = false
local Workspace = game.Workspace
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild('Humanoid')
local animation = script.Animation
local TimeStop = game.ReplicatedStorage.TimeStop
local AnimationTrack = humanoid:LoadAnimation(animation)
if not bool then
bool = true
UIS.InputBegan:Connect(function(input, chat)
if chat then
return
elseif input.KeyCode == Enum.KeyCode.Q then
AnimationTrack:Play()
humanoid.WalkSpeed = 0
TimeStop:FireServer()
wait(1)
humanoid.WalkSpeed = 16
end
end)
end
Server
local UIS = game:GetService("UserInputService")
local lighting = game.Lighting
local bool = false
local Workspace = game.Workspace
local TimeStop = game.ReplicatedStorage.TimeStop
local Players = game.Players:GetPlayers()
TimeStop.OnServerEvent:Connect(function (player)
print(player.Name.."Has Stopped Time!")
if bool == false then
lighting.ColorCorrection.Saturation = -3
for i, v in pairs(Workspace:GetChildren()) do
if v.Name == "Rock" or v:IsA("SpawnLocation") then
game.Workspace.Rain.RainScript.Disabled = true
v.Anchored = true
end
end
for i, v in pairs(game.Players:GetChildren()) do
if v ~= player then
for i, v in pairs(v.Character:GetChildren()) do
if v:IsA("BasePart") then
v.Anchored = true
end
end
end
end
else
lighting.ColorCorrection.Saturation = 0
for i, v in pairs(Workspace:GetChildren()) do
if v.Name == "Rock" or v:IsA("SpawnLocation") then
game.Workspace.Rain.RainScript.Disabled = false
v.Anchored = false
end
end
for i, v in pairs(game.Players:GetChildren()) do
if v ~= player then
for i, v in pairs(v.Character:GetChildren()) do
if v:IsA("BasePart") then
v.Anchored = false
end
end
end
end
end
bool = true
end)
When i play the game, the script runs but only one time.
As shown im pressing Q multiple times (you can tell since the animation is playing) but nothing happens
Im still learning alot about scripting so a somewhat simple explanation would be greatly apricated!
I took python classes before and I remember hearing that if you add a for i = … loop inside ANOTHER for i = … loop then the inside loop’s i overrides the outer loop’s i. Not really sure if this also applies in lua pairs and the 2nd variable (v), but change the inner loop’s 2nd variable (v) to e or something and do the same with other nested loops
You aren’t resetting the bool value back to false here. This causes it to run once.
Here is a fixed version. Just put bool = false wherever you stop the code.
if not bool then
bool = true
UIS.InputBegan:Connect(function(input, chat)
if chat then
return
elseif input.KeyCode == Enum.KeyCode.Q then
AnimationTrack:Play()
humanoid.WalkSpeed = 0
TimeStop:FireServer()
wait(1)
humanoid.WalkSpeed = 16
bool = false
end
end)
end
It happens over here too. You aren’t resetting the value back to false.