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?
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