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

Why can't I adjust the Value of a BoolValue?

I have a BoolValue called InGame in the StarterPack with a Value of false. In the ServerScriptService, I have one script with the following code:

local plrs = game.Players:GetChildren()
for _, child in ipairs(plrs) do
	child:WaitForChild("Backpack"):WaitForChild("InGame").Value = true
	print(child:WaitForChild("Backpack"):WaitForChild("InGame").Value)
	child:LoadCharacter()
end

This outputs True, which is the new Value of InGame for each Player. In another script (also in ServerScriptService) I have the following code:

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		print(player:WaitForChild("Backpack"):WaitForChild("InGame").Value)
		if player:WaitForChild("Backpack"):WaitForChild("InGame").Value then
			character.Humanoid.WalkSpeed = 30
			character.Humanoid.JumpPower = 200
		end
	end)
end)

This outputs False, which is the actual value of InGame for each Player. Thus, the WalkSpeed and JumpPower properties aren't changed. What am I doing wrong?

1 comment

0

This should all be managed on the server then have a remote to toggle the value

1 answer

✓ Accepted answer

This is actually a really simple fix!

You see, where you put the value is not ideal, because each time they spawn they get the same false value from starterpack. Because you set the value to true in each player, then spawn them, it's giving them a False valued BoolVal once they spawn. So when you set the value in each player to "true", but then spawn them in, then it "refreshes" their backpack, giving them the false valued BoolVal.

What I suggest is putting the value in the player as soon as they join using Instance.new. This is better because you can easily edit each player's value without having to go into backpack.

Here's what i'd do:

game.Players.PlayerAdded:connect(function(plr)
a =I nstance.new("BoolValue")
a.Name = ("InGame")
a.Parent=p
a.Value=false
end)

For the first script, i'd simply change it to:

local plrs = game.Players:GetChildren()
for _, child in ipairs(plrs) do
    child:WaitForChild("InGame").Value = true
    child:LoadCharacter()
end

For your second script, i'd edit a few lines like this:

for k,player in pairs (game.Players:GetPlayers()) do
    player.CharacterAdded:connect(function(character)
        if player:WaitForChild("InGame").Value then
            character.Humanoid.WalkSpeed = 30
            character.Humanoid.JumpPower = 200
           end
        end
    end)
end

2 comments

0

When I put this into the script, it didn't work...but when I took the "for k, player in pairs..." out and added "game.Players.PlayerAdded:connect(function(character) instead, it did. Thanks anyway!

0

Yeah sorry, i'm doing this at my school (So I dont have access to studio) and I dont have a way to double check if they work.

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