Cannot parent IntValue to Player

Theres not much to say other than this very simple code which is suppose to parent an IntValue to the player, is not doing its thing. There are also no errors.

This is a server script stored in StarterCharacterScripts

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer

local ColourValue = Instance.new("IntValue")
ColourValue.Name = "PlayerColour"
ColourValue.Parent = LocalPlayer -- For some reason this doesn't work
print(ColourValue.Parent) -- returns nil. aaaaah

Does anyone know what’s wrong here?

You cannot use Local Player in a Server Script, that only works in Local Scripts. I would recommend using the following in a server script in ServerScriptService:

game.Players.PlayerAdded:Connect(function(player)
       local ColourValue = Instance.new("IntValue")
       ColourValue.Name = "PlayerColour"
       ColourValue.Parent = Player
       print(ColourValue.Parent)

end)
1 Like

omg, I am so stupid. I completely forgot about that. Thank you sir!

2 Likes