Need help with putting IntValues in player character

I need help with putting IntValue in the player’s character. I put this code in SeverScriptService.

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	local Value = Instance.new("IntValue")
	Value.Name = 'Mana'
	Value.Value = 100
	Value.Parent = player
end)

화면 캡처 2023-08-02 154620
I can’t figure out why it’s not working.

3 Likes

From what you gave shared it seems to be a simple issue.

(As of writing this, I am not in Roblox Studio so you may have to check for syntax.)

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
    local Character = player.Character or Player.CharacterAdded:Wait()
    local Value = Instance.new("IntValue")
    Value.Name = 'Mana'
    Value.Value = 100
    Value.Parent = Character
end)

When you create a new IntValue (in this case local Value = Instance.new("IntValue") ), you parent it to the player. The int value is actually in the player from the PlayerService and not the Workspace from that player.

Instead, you should reference the Character and then set the IntValue to the Character.

2 Likes

Thanks for the solution. It solved!
image

or you can just basically write it like that too…
(ik the problem is probably solved, but i wanted to show an alternative way for that…)

game.Players.PlayerAdded:Connect(function(player)
    local Character = player.Character
    local Value = Instance.new("IntValue", Character) -- Basically, second parameter becomes the parent of new instance
    Value.Name = "Mana"
    Value.Value = 100

end)

But just a reminder: After dying, your character will lose your mana stat. You can do this instead if you don’t want to lose it…

game.Players.PlayerAdded:Connect(function(player)
   player.CharacterAdded:Connect(function(Character)
    local Value = Instance.new("IntValue",Character)
    Value.Name = "Mana"
    Value.Value = 100
end)
end)

I’m not in the Studio too, you may need to check syntaxes

1 Like

Thanks for supplementing the solution

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.