Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesn't this script work if the boolvalue is true?

Asked by 6 years ago

I am trying to make this script work when a specific boolvalue is true, but the problem is, it won't detect the boolvalue. Here is the script:

--- all this is just buttons and gui stuff ---
local pow = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("PowerGui2"):WaitForChild("Frame")
local speed = pow.Select1
local invis = pow.Select2
-----------------------------------------------------
local m = game.Players.LocalPlayer:GetMouse()
db = true

if speed.Value.Value == true then 
---- the stuff below is not important because I tested it and it works ---
    m.KeyDown:Connect(function(k)
        if k == "q" then
            if db == true then
                game.ReplicatedStorage.Speedparticle:Clone().Parent = game.Players.LocalPlayer.Character:FindFirstChild("UpperTorso")
                game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed = 40
                db = false
                wait(10)
                    game.Players.LocalPlayer.Character:FindFirstChild("UpperTorso").Speedparticle:Remove()
                db = true
                game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed = 16
            end
        end
    end)   
end

0
its important because KeyDown is deprecated. use UserInputService.InputBegan instead Gey4Jesus69 2705 — 6y
0
Deprecated doesn't mean not working. KeyDown works for most keys and UserInputService can be a bit harder for people to understand. clc02 553 — 6y
0
Terrible argument. You shouldn't be using Deprecated items. Don't teach bad practices. xPolarium 1388 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

I've moved the speed value check to the following if statement. With this when Key Down is connected it will check if speed value is true and the right key is pressed. Hope this helps

--- all this is just buttons and gui stuff ---
local pow = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("PowerGui2"):WaitForChild("Frame")
local speed = pow.Select1
local invis = pow.Select2
-----------------------------------------------------
local m = game.Players.LocalPlayer:GetMouse()
db = true

---- the stuff below is not important because I tested it and it works ---
m.KeyDown:Connect(function(k)
    if speed.Value.Value == true and k == "q" then
        if db == true then
            game.ReplicatedStorage.Speedparticle:Clone().Parent = game.Players.LocalPlayer.Character:FindFirstChild("UpperTorso")
            game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed = 40
            db = false
            wait(10)
                game.Players.LocalPlayer.Character:FindFirstChild("UpperTorso").Speedparticle:Remove()
            db = true
            game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed = 16
        end
    end
end)


Ad

Answer this question