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

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

Asked by 7 years ago

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?

0
This should all be managed on the server then have a remote to toggle the value User#5423 17 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

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

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! jamesarsenault 192 — 7y
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. Tempestatem 884 — 7y
Ad

Answer this question