Ad
Log in to vote
0

I'm trying to make it so you can only do an ability when you are holding an item, but it won't work?

Asked by 6 months ago

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)

2 answers

Log in to vote
0
Answered by 6 months ago

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.

0
use "task.wait()" if pro, performance difference is very noticeable, create 1000 small parts and move each of them by a bit every "wait()", then try the same with "task.wait()" imKirda 4065 — 6mo
0
Thank you, I will see if this works! The reason I used the wait() was because I was trying to make a cooldown. DriBowser 49 — 6mo
0
Yep, it works! Thank you so much! DriBowser 49 — 6mo
0
If you wanna make a cooldown, you can add the wait(55) after you put enabled = false. After that, you can add enabled = true after wait(55). The cooldown will be 55 seconds. AProgrammR 378 — 6mo
Ad
Log in to vote
0
Answered by 6 months ago

Im not really advance with scripting but maybe Instead use a GUI button that will activate It

0
No, you can use a tool. VitroxVox 879 — 6mo

Answer this question