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 5 years ago

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

01local SuperSpeed = script:WaitForChild("SuperSpeed")
02local Fast = script:WaitForChild("Fast")
03local Intermediate = script:WaitForChild("Intermediate")
04local Slow = script:WaitForChild("Slow")
05local CharacterSpeed = script:WaitForChild("CharacterSpeed")
06 
07if SuperSpeed.Value == true then
08    print("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
09    game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 157
10    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 — 5y
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 — 5y
0
provided is a bit confusing 0msh 333 — 5y
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 — 5y
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 — 5y

2 answers

Log in to vote
0
Answered by
bluzorro 417 Moderation Voter
5 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.

01local SuperSpeed = script:WaitForChild("SuperSpeed")
02local Fast = script:WaitForChild("Fast")
03local Intermediate = script:WaitForChild("Intermediate")
04local Slow = script:WaitForChild("Slow")
05local CharacterSpeed = script:WaitForChild("CharacterSpeed")
06 
07SuperSpeed.Changed:Connect(function()
08    if SuperSpeed.Value == true then
09         print("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
10         game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 157
11         CharacterSpeed.Value = 157
12    end
13end)
Ad
Log in to vote
0
Answered by 5 years ago
1local BoolValue  = Instance.new("BoolValue")
2BoolValue.Parent = script
3BoolValue.Value  = true
4 
5if BoolValue.Value then
6    print('ebic!')
7end

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 — 5y
0
then use WaitForChild for when you're trying to find the bool value? User#31525 30 — 5y

Answer this question