Why aren't my leaderstats showing up?

I’m making a little simulator for fun and my script aint working, the leaderstats won’t show up. Whats wrong with it?

My code
local datastore = game:GetService("DataStoreService")
local data1 = datastore:GetDataStore("mystrengthdata")
local data2 = datastore:GetDataStore("myleveldata")
local data3 =  datastore:GetDataStore("mygolddata")

game.Players.PlayerAdded:connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local Level = Instance.new("IntValue", leaderstats)
Level.Name = "Level"
local Gold = Instance.new("IntValue", leaderstats)
Gold.Name = "Gold"
local strength = Instance.new("IntValue", leaderstats)
strength.Name = "strength"
strength.Value = data1:GetAsync(player.UserId) or 0
data1:SetAsync(player.UserId, strength.Value)
Level.Value = data2:GetAsync(player.UserId) or 0
data2:SetAsync(player.UserId, Level.Value)
Gold.Value = data3:GetAsync(player.UserId) or 0
data3:SetAsync(player.UserId, Gold.Value)

game.Players.PlayerRemoving:connect(function()
data1:SetAsync(player.UserId, strength.Value)
data2:SetAsync(player.UserId, Level.Value)
data3:SetAsync(player.UserId, Gold.Value)
Exp.Changed:connect(function() ExpChange(Player,Exp,Level) 
end)
end)
end)
function ExpChange(Player,strength,Level)
	if strength.Value >= Level.Value* then
		strength.Value = 0
		Level.Value = Level.Value + 1
	end
end

I don’t know what I did wrong.

Where is this script, being handled?

It’s being handled in ServerScriptService

Are there any errors? (sorry if i seem like i am asking too many questions)

Yes, one, here

if strength.Value >= Level.Value* then

then is an error. "Expected identifier when parsing expression, got ‘then’

And I don’t mind the questions, they’re helping me fix my code. :slight_smile:

You put a * but didn’t multiply by anything.

2 Likes

i believe, i know the problem( or at least part of it) , Firstly i’m pretty sure you need to shift around your code a little bit, separate the player added and player removing function. The parsing error was because of this * that was next to Level.Value

local datastore = game:GetService("DataStoreService")
local data1 = datastore:GetDataStore("mystrengthdata")
local data2 = datastore:GetDataStore("myleveldata")
local data3 =  datastore:GetDataStore("mygolddata")

game.Players.PlayerAdded:connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local Level = Instance.new("IntValue", leaderstats)
Level.Name = "Level"
local Gold = Instance.new("IntValue", leaderstats)
Gold.Name = "Gold"
local strength = Instance.new("IntValue", leaderstats)
strength.Name = "strength"
strength.Value = data1:GetAsync(player.UserId) or 0
data1:SetAsync(player.UserId, strength.Value)
Level.Value = data2:GetAsync(player.UserId) or 0
data2:SetAsync(player.UserId, Level.Value)
Gold.Value = data3:GetAsync(player.UserId) or 0
data3:SetAsync(player.UserId, Gold.Value)

end)

game.Players.PlayerRemoving:connect(function()
data1:SetAsync(player.UserId, strength.Value)
data2:SetAsync(player.UserId, Level.Value)
data3:SetAsync(player.UserId, Gold.Value)
Exp.Changed:connect(function() ExpChange(Player,Exp,Level) 
end)



function ExpChange(Player,strength,Level)
	if strength.Value => Level.Value then
		strength.Value = 0
		Level.Value = Level.Value + 1
	end
end
1 Like

Aye the leaderstats popped back up but the punch wont add strength

is there any error in this? other than inproper capitalization

	player.leaderstats.strength.Value = player.leaderstats.strength.Value + 1*player.leaderstats.level.Value  
end)

Not that i can see, from what i can tell it’s muliplying 1 and player.leaderstats.level.Value and adding player.leaderstats.level.Value , also i am guessing that is part of a script, since you have end)

I’m trying to add 1 strength and multiply it by the level of the player.

in that case just flip around your values so that it does that:

 player.leaderstats.level.Value = (player.leaderstats.level.Value + 1) *player.leaderstats.level.Value

Ok imma try that. I tried this, but it didnt work.

local Level = player.leaderstats.Level.Value
	player.leaderstats.strength.Value = player.leaderstats.strength.Value + 1*Level

wait thats adding the level t itself? (in the one you provided)

1 Like

yeah, made a mistake i meant to do this:

 player.leaderstats.strength.Value = (player.leaderstats.strength.Value + 1) *player.leaderstats.level.Value

Trying that now. :stuck_out_tongue:

It’s not working. Maybe an error in the punching script. :confused: thank you going through all this and helping me! :slight_smile:

In this example you are mistaking your order of operations. First the multiplication is done, then the addition. To prevent the level from multiplying before 1 is added, as @Jaycbee05 wrote, you need to put the value+1 into parenthesis so that the order of operations knows not to multiply first.

2 Likes

Do you have any new errors in the output?