How to create a StringValue on the player

Basiclly the title says it how do I add a StringValue to a player via script
Ik i have to use instance.new
Where I want to add StringValue:
image
Pls help me

game.Players.PlayerAdded:Connect(function(plr)
	local IntValue = Instance.new("IntValue")
	IntValue.Value = 0
    IntValue.Name = "Name"
	IntValue.Parent = plr
end)

Hi! I would recommend always using game:GetService on any of the main services.

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	local IntValue = Instance.new("IntValue")
	IntValue.Parent = Player
end)

1 question, intavlue is a text value right?

There is no need for that when working on server, it’s mainly useful when working on client and with remotes, etc. In this case, you dont have to get its service.
The code @alphadoggy111 provided will work fine with no errors.

[Yours will work aswell :)]

No, StringValue is text. IntValue will contain numbers, and NumberValue will contain numbers with decimals :slight_smile:

then in this case its a string value i wanna make

the value is different for each player

Why do you want to create a StringValue on/under the player?

I’m confused - what are you trying to represent with each IntValue?

You say you want a different value for each player, but you haven’t gone in depth on what you want that value to actually represent.

I jst want to make a value that is different for each player.
For example: I want to make a value that states the Nickname of the player

??? Still doesn’t contradict my statement.

You could just name that value in the Player’s name :



game.Players.PlayerAdded:Connect(function(Player)
	local IntValue = Instance.new("IntValue")
	IntValue.Parent = Player
    IntValue.Name = Player.Name 
    --optional
    IntValue.Value = Player.UserId
end)

Why not use attributes for that?

game.Players.PlayerAdded:Connect(function(player)
    player:SetAttribute("Nickname", "default value")
end)

I would think it’s much simpler than managing instances.

I would recommend organising your values in a folder inside the player then. Later you can add even more values if needed! :slight_smile:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	local ValueFolder = Instance.new("Folder")
	ValueFolder.Name = "ValueFolder"

	local ValueNickname = Instance.new("StringValue")
	ValueNickname.Name = "Nickname"
	ValueNickname.Value = Player.DisplayName
	ValueNickname.Parent = ValueFolder

	-- Add more values if needed!

	ValueFolder.Parent = Player
end)

I would also highly recommend using this over creating values in the players.