Why this cide doesn't work?

why this code don’t work?

game.Players.PlayerAdded:Connect(function(player)
	local stat = Instance.new("Folder", player)
	stat.Name = "stats"
	
	local money = Instance.new("IntValue")
	money.Name = "Money"
	money.Value = 0
	money.Parent = player.stats
	
	local MUpgrade = Instance.new("IntValue")
	MUpgrade.Name = "Mupgrade"
	MUpgrade.Value = 1
	MUpgrade.Parent = player.stats
	
	local ups = Instance.new("IntValue")
	ups.Name = "Mups"
	ups.Value = 0
	ups.Parent = player.stats
	
	local rebs = Instance.new("IntValue")
	rebs.Name = "rebs"
	rebs.Value = 0
	rebs.Parent = player.stats
	
	local rank = Instance.new("IntValue")
	rank.Name = "Rank"
	rank.Value = 0
	rank.Parent = player.stats
	
	local x = Instance.new("IntValue")
	if rank.Value == 1 then
		x.Value = 1
	elseif rank.Value == 2 then
		x.Value = 3
	end
	
	while wait(1) do
		money.Value += 1 * MUpgrade.Value * rebs.Value * x.Value
	end
end)

everything is fine except

 while wait(1) do
	money.Value += 1 * MUpgrade.Value * rebs.Value * x.Value

or maybe with x.Value

for exception when it was just

 while wait(1) do
	money.Value += 1 * MUpgrade.Value * rebs.Value

everything works right but not this does nothing
(sorry if bad english it’s not my national language)

Rank’s value is originally set as 0, and since x isn’t set to 1 or 3, it stayed 0 (default value), therefore it doesn’t add money (or add 0 money since you are multiplying a number with 0). All you need is set rank.Value to 1 or 2 instead of 0

i replaced but it still doesnt do anything (player doesnt getting money)

also added + 1 to rebs.Value but now it just does + 1 and doesnt multiple with upgrades

	local rank = Instance.new("IntValue")
	rank.Name = "Rank"
	rank.Value = 0
	rank.Parent = player.stats
	
	local x = Instance.new("IntValue")
	if rank.Value == 0 then
		x.Value = 1
	elseif rank.Value == 1 then
		x.Value = 3
	end
	
	while wait(1) do
		money.Value += 1 * MUpgrade.Value * rebs.Value + 1 * x.Value
	end
end)

Looks like MUpgrade.vale == 1, rebs.Value == 1, and x.Value == 1 so “1x1x1==1”
Why don’t you try to set MUpgrade.value to 2, rebs.Value to 2, x.Value to 2, and see if the money is set to 8, to check the rest of your script.

yes this works but im need to player starts from +1 and get upgrades to get more money

You could use an if statement and do something like

if  MUpgrade.value<=1 and rebs.Value<=1 and x.Value<=1 then
      money.Value == whatever you want it to be
else 
      money.Value += 1 * MUpgrade.Value * rebs.Value + 1 * x.Value
end

I am not sure exactly how much money you want the player to start with, or what exactly your plans are for the stats, but if you told me more about how you want the player to start, I could probably give more specific help.


(tried your code but it still the same)

It’s probably because you are adding the values on a local script, which won’t be changed on the server. If this is the case, try to use remote events and change it on the server, along with that can you show the local script that handles the button? (IF you are changing the values on the local script)

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