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

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

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

3 comments

0

its important because KeyDown is deprecated. use UserInputService.InputBegan instead

0

Deprecated doesn't mean not working. KeyDown works for most keys and UserInputService can be a bit harder for people to understand.

0

Terrible argument. You shouldn't be using Deprecated items. Don't teach bad practices.

1 answer

✓ Accepted answer

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)


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