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

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

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,

5 comments

0

Is it possible it is not being set until after it checks if the variable is true? Maybe you need to wait

0

you need to provide more code or finish your script, because you're missing an "end" at the end and what you

0

provided is a bit confusing

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.)

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.

2 answers

✓ Accepted answer

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)
local BoolValue  = Instance.new("BoolValue")
BoolValue.Parent = script
BoolValue.Value  = true

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

I hope this helps out.

2 comments

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.

0

then use WaitForChild for when you're trying to find the bool value?

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