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

Why doesnt my code run even though Value is set to true?

Asked by 4 years ago

im having a problem where my value is setting to true but my code doesnt run,

local SuperSpeed = script:WaitForChild("SuperSpeed")
local Fast = script:WaitForChild("Fast")
local Intermediate = script:WaitForChild("Intermediate")
local Slow = script:WaitForChild("Slow")
local CharacterSpeed = script:WaitForChild("CharacterSpeed")

if SuperSpeed.Value == true then
    print("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
    game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 157
    CharacterSpeed.Value = 157

i have a separate GUI to set the SuperSpeed Value to True, and it is setting it. but none of the code for the Value being true is being run,

0
Is it possible it is not being set until after it checks if the variable is true? Maybe you need to wait proqrammed 285 — 4y
0
you need to provide more code or finish your script, because you're missing an "end" at the end and what you 0msh 333 — 4y
0
provided is a bit confusing 0msh 333 — 4y
0
i only provided that part of the script because everything else is just the same coding but for the other Values (Fast,Intermediate etc etc.) Roviospace 22 — 4y
0
Is script in the GUI a localscript? If then it explains why it may not work because localscripts only affect “The client” not the server . To affect the server you need to use “Remote Events”. Watch a tutorial on “Remote Events” to better understand how it works. St_vnC 330 — 4y

2 answers

Log in to vote
0
Answered by
bluzorro 417 Moderation Voter
4 years ago

The problem is that the statement checks if the value is true before the value was even set to true. In order to prevent this, you can use the Changed event.

local SuperSpeed = script:WaitForChild("SuperSpeed")
local Fast = script:WaitForChild("Fast")
local Intermediate = script:WaitForChild("Intermediate")
local Slow = script:WaitForChild("Slow")
local CharacterSpeed = script:WaitForChild("CharacterSpeed")

SuperSpeed.Changed:Connect(function()
    if SuperSpeed.Value == true then
         print("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
         game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 157
         CharacterSpeed.Value = 157
    end
end)
Ad
Log in to vote
0
Answered by 4 years ago
local BoolValue  = Instance.new("BoolValue")
BoolValue.Parent = script
BoolValue.Value  = true

if BoolValue.Value then
    print('ebic!')
end

I hope this helps out.

0
this doesnt work for my case because i need other scripts to function differently depending if SuperSpeed or Fast etc is set to True. Roviospace 22 — 4y
0
then use WaitForChild for when you're trying to find the bool value? User#31525 30 — 4y

Answer this question