Ok, so I am trying to do an ability where you can stop time only when you are holding a sword. So, here is the problem. It works fine the first time before I pull out my sword, when you press the button, it will only do it when you are holding the sword. But after, even when you aren't holding the sword, it still stops time! Does anyone have any ideas what i need to do? Thank you.
Also, i have tried wrapping it in a loop, but that just crashes it. (also, this isn't required but I'm wondering how i could put an animation to play when you do it. Thanks!
Here is the script: (It's a local script inside the tool)
local UIS = game:GetService("UserInputService") local tool = script.Parent local player = game.Players.LocalPlayer local enabled = false local remote = game:GetService("ReplicatedStorage"):FindFirstChild("TimeStop") tool.Equipped:Connect(function() UIS.InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.E then if enabled == false then enabled = true remote:FireServer("TimeStop") for i=70, 100,5 do wait() workspace.Camera.FieldOfView = i end for i=100, 70,-5 do wait() workspace.Camera.FieldOfView = i end wait(55) enabled = false end end end) end)
Try rewriting your code just a bit like this.
local UIS = game:GetService("UserInputService") local tool = script.Parent local player = game.Players.LocalPlayer local enabled = false local remote = game:GetService("ReplicatedStorage"):FindFirstChild("TimeStop") tool.Equipped:Connect(function() enabled = true end) tool.Unequipped:Connect(function() enabled = false -- You can write a code for the time to go on here end) UIS.InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.E then if enabled == true then remote:FireServer("TimeStop") for i=70, 100,5 do wait() workspace.Camera.FieldOfView = i end for i=100, 70,-5 do wait() workspace.Camera.FieldOfView = i end end end end)
And btw, why do you need the 'wait(55)' part.
Im not really advance with scripting but maybe Instead use a GUI button that will activate It