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

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

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

✓ Accepted answer

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)

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)

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.

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