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.

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

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.

game.Players.PlayerAdded:connect(function(plr)
    local OwnsTycoon = Instance.new('BoolValue',  plr)
    OwnsTycoon.Value = false
    OwnsTycoon.Name = 'OwnsTycoon'
end)

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.

local player = game.Players.LocalPlayer
game.Players.PlayerAdded:connect(function(plr)
    local OwnsTycoon = Instance.new("BoolValue")
    OwnsTycoon.Parent = player
    OwnsTycoon.Value = false
    OwnsTycoon.Name = "OwnsTycoon"
end)
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.

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


I simply explained the same thing DepressionSensei did.

Answer this question