Player Stats can't be changed

Hi! I recently make a new project that basically gives player some in-game stats. And I want to allow players to manually upgrade it. However, when I do that there was an error.(If you are wondering what the error is basically is a script is attempting to change an instance and value) I know what it’s means but, since I started script not really long ago, I don’t know much thing. Is there anyone tell me how I can solve this bug? Thx :smiley:

Can you show the script so we can help?

sure I can do that, just wait me a bit copying and pasting it

Code to give player stats:

game.Players.PlayerAdded:Connect(function(player)
	local PlayerStats = Instance.new("Folder",player)
	PlayerStats.Name = "PlayerStats"
	
	local ATP = Instance.new("IntValue",PlayerStats)
	ATP.Name = "AttackPower"
	ATP.Value = 100
	
	local Def = Instance.new("IntValue",PlayerStats)
	Def.Name = "Defense"
	Def.Value = 100
	
	local HP = Instance.new("IntValue",PlayerStats)
	HP.Name = "Health"
	HP.Value = 120
	
	local AGT = Instance.new("IntValue",PlayerStats)
	AGT.Name = "Agility"
	AGT.Value = 100
end)

Button that send the event and server that recived the event:

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.ATPChanged:FireServer()
	print("It got clicked!")
end)
game.ReplicatedStorage.ATPChanged.OnServerEvent:Connect(function(player)
	print("It recived!")
	local PlayerATP = player.PlayerStats.AttackPower
	PlayerATP.Value = PlayerATP + 20
end)

change this to PlayerATP.Value

game.ReplicatedStorage.ATPChanged.OnServerEvent:Connect(function(player)
	print("It recived!")
	local PlayerATP = player.PlayerStats.AttackPower
	PlayerATP.Value = PlayerATP.Value + 20
end)
1 Like

oo yea sorry DUDE HOW CAN I LITERALLY FORGET THIS BRUH ;-;

anyways still thx to your solution Idk how I can’t spot that ;-;