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

Why does this script fail to add an IntValue inside Players?

Asked by 8 years ago

Hello, why wont this work? It does not create the IntValue nor it errors.

1game.Players.PlayerAdded:connect(function(plr)
2    local OwnsTycoon = Instance.new('IntValue' , game.Players:FindFirstChild(plr))
3    OwnsTycoon.Value = false
4    OwnsTycoon.Name = 'OwnsTycoon'
5end)

3 answers

Log in to vote
2
Answered by 8 years ago
Edited 8 years ago

Why are you searching for the plr argument in Players? It is already defined as the player.

1game.Players.PlayerAdded:connect(function(plr)
2    local OwnsTycoon = Instance.new('BoolValue',  plr)
3    OwnsTycoon.Value = false
4    OwnsTycoon.Name = 'OwnsTycoon'
5end)
Ad
Log in to vote
0
Answered by
nanaluk01 247 Moderation Voter
8 years ago
Edited 8 years ago

You have forgotten to tell the script who the player is.

Also: an IntValue cannot have a false or true value. Only numbers. Therefore your value has to be a BoolValue.

1local player = game.Players.LocalPlayer
2game.Players.PlayerAdded:connect(function(plr)
3    local OwnsTycoon = Instance.new("BoolValue")
4    OwnsTycoon.Parent = player
5    OwnsTycoon.Value = false
6    OwnsTycoon.Name = "OwnsTycoon"
7end)
Log in to vote
0
Answered by 8 years ago

DepressionSensei is correct. You already have the player, passed down as "plr". Finding the player would only cause problems, compared to directly affecting the player (because you already have him/her as "plr" when they join). On another note, you cannot set a IntValue to true or false. A "IntValue" stands for "Integer Value" which is commonly received as a number value. A BoolValue, or sometimes called a boolean, is a True or False value. Your code can check the value and act depending on whether it is true or false.

1game.Players.PlayerAdded:connect(function(plr) -- Right here, plr is the player that joined
2    local OwnsTycoon = Instance.new('BoolValue',  plr)  -- This creates a new "BoolValue", right under plr(which is the player, passed down through the script)
3    OwnsTycoon.Value = false -- Now you are dealing with a boolean, and that can have a true/false value
4    OwnsTycoon.Name = 'OwnsTycoon'
5end)

I simply explained the same thing DepressionSensei did.

Answer this question