[Help Needed!] Speed Upgrade shop not working

Hi everyone! I have scripted a speed upgrade shop but it isn’t working. Here is the script: (local)

local player = game.Players.LocalPlayer
local nowalkspeed = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed
script.Parent.Text = "30 Coins"
local AmountLeft = script.Parent.Parent.AmountOfUpgrades.AmountLeft
local AmountUpgraded = script.Parent.Parent.AmountOfUpgrades.AmountUpgraded
script.Parent.Parent.AmountOfUpgrades.Text = AmountUpgraded.Value.." / "..AmountLeft.Value
script.Parent.MouseButton1Click:Connect(function()
	print("pressed upgrade")
	script.Parent.Parent.AmountOfUpgrades.Text = AmountUpgraded.Value.." / "..AmountLeft.Value
	
	
	if AmountUpgraded.Value == 2 then
		if player:WaitForChild("leaderstats").Coins.Value >= 30 then
			player:WaitForChild("leaderstats").Coins.Value -= 30
			AmountUpgraded.Value = AmountUpgraded.Value + 1
			game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = nowalkspeed + 5
			script.Parent.Text = "50 Coins"
			print(game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed)
		else
			print(player.Name.. " doesn't have enough coins to upgrade")
			script.Parent.BackgroundColor3 = Color3.new(1, 0, 0.0156863)
			script.Parent.Text = "Not Enough Coins!!"
			task.wait(1)
			script.Parent.BackgroundColor3 = Color3.new(1, 0.85098, 0)
			script.Parent.Text = "50 Coins"
		end
	elseif AmountUpgraded.Value == 3 then
		if player:WaitForChild("leaderstats").Coins.Value >= 50 then
			player:WaitForChild("leaderstats").Coins.Value -= 50
			game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = nowalkspeed + 10
			script.Parent.Text = "100 Coins"
			print(game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed)
		else
			print(player.Name.. " doesn't have enough coins to upgrade")
			script.Parent.BackgroundColor3 = Color3.new(1, 0, 0.0156863)
			script.Parent.Text = "Not Enough Coins!!"
			task.wait(1)
			script.Parent.BackgroundColor3 = Color3.new(1, 0.85098, 0)
			script.Parent.Text = "100 Coins"
		end
	elseif AmountUpgraded.Value == 4 then
		if player:WaitForChild("leaderstats").Coins.Value >= 100 then
			player:WaitForChild("leaderstats").Coins.Value -= 100
			game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = nowalkspeed + 15
			script.Parent.Text = "150 Coins"
			print(game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed)
		else
			print(player.Name.. " doesn't have enough coins to upgrade")
			script.Parent.BackgroundColor3 = Color3.new(1, 0, 0.0156863)
			script.Parent.Text = "Not Enough Coins!!"
			task.wait(1)
			script.Parent.BackgroundColor3 = Color3.new(1, 0.85098, 0)
			script.Parent.Text = "150 Coins"
		end
	elseif AmountUpgraded.Value == 5 then
		if player:WaitForChild("leaderstats").Coins.Value >= 150 then
			player:WaitForChild("leaderstats").Coins.Value -= 150
			game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = nowalkspeed + 20
			script.Parent.Text = "200 Coins"
			print(game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed)
		else
			print(player.Name.. " doesn't have enough coins to upgrade")
			script.Parent.BackgroundColor3 = Color3.new(1, 0, 0.0156863)
			script.Parent.Text = "Not Enough Coins!!"
			task.wait(1)
			script.Parent.BackgroundColor3 = Color3.new(1, 0.85098, 0)
			script.Parent.Text = "200 Coins"
		end
	elseif AmountUpgraded.Value == 6 then
		if player:WaitForChild("leaderstats").Coins.Value >= 200 then
			player:WaitForChild("leaderstats").Coins.Value -= 200
			game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = nowalkspeed + 25
			script.Parent.Text = "250 Coins"
			print(game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed)
		else
			print(player.Name.. " doesn't have enough coins to upgrade")
			script.Parent.BackgroundColor3 = Color3.new(1, 0, 0.0156863)
			script.Parent.Text = "Not Enough Coins!!"
			task.wait(1)
			script.Parent.BackgroundColor3 = Color3.new(1, 0.85098, 0)
			script.Parent.Text = "250 Coins"
		end
	elseif AmountUpgraded.Value == 7 then
		if player:WaitForChild("leaderstats").Coins.Value >= 250 then
			player:WaitForChild("leaderstats").Coins.Value -= 250
			game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = nowalkspeed + 30
			script.Parent.Text = "300 Coins"
			print(game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed)
		else
			print(player.Name.. " doesn't have enough coins to upgrade")
			script.Parent.BackgroundColor3 = Color3.new(1, 0, 0.0156863)
			script.Parent.Text = "Not Enough Coins!!"
			task.wait(1)
			script.Parent.BackgroundColor3 = Color3.new(1, 0.85098, 0)
			script.Parent.Text = "300 Coins"
		end
	elseif AmountUpgraded.Value == 8 then
		if player:WaitForChild("leaderstats").Coins.Value >= 300 then
			player:WaitForChild("leaderstats").Coins.Value -= 300
			game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = nowalkspeed + 35
			script.Parent.Text = "350 Coins"
			print(game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed)
		else
			print(player.Name.. " doesn't have enough coins to upgrade")
			script.Parent.BackgroundColor3 = Color3.new(1, 0, 0.0156863)
			script.Parent.Text = "Not Enough Coins!!"
			task.wait(1)
			script.Parent.BackgroundColor3 = Color3.new(1, 0.85098, 0)
			script.Parent.Text = "350 Coins"
		end
	elseif AmountUpgraded.Value == 9 then
		if player:WaitForChild("leaderstats").Coins.Value >= 350 then
			player:WaitForChild("leaderstats").Coins.Value -= 350
			game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = nowalkspeed + 40
			script.Parent.Text = "400 Coins"
			print(game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed)
		else
			print(player.Name.. " doesn't have enough coins to upgrade")
			script.Parent.BackgroundColor3 = Color3.new(1, 0, 0.0156863)
			script.Parent.Text = "Not Enough Coins!!"
			task.wait(1)
			script.Parent.BackgroundColor3 = Color3.new(1, 0.85098, 0)
			script.Parent.Text = "400 Coins"
		end
	elseif AmountUpgraded.Value >= 10 then
		if player:WaitForChild("leaderstats").Coins.Value >= 400 then
			player:WaitForChild("leaderstats").Coins.Value -= 400
			game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = nowalkspeed + 10
			script.Parent.Text = "MAXED"
			print(game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed)
		else
			print(player.Name.. " doesn't have enough coins to upgrade")
			script.Parent.BackgroundColor3 = Color3.new(1, 0, 0.0156863)
			script.Parent.Text = "Not Enough Coins!!"
			task.wait(1)
			script.Parent.BackgroundColor3 = Color3.new(1, 0.85098, 0)
			script.Parent.Text = "MAXED"
		end
	end
end)

It would probably be useful for anyone trying to help to know that “pressed upgrade” does print in the output.

3 Likes

Try checking if the “AmountUpgraded.Value == #” conditions are working by printing something if the condition is true.

1 Like

Nothing seems to be printing when I do this.

Then the issue is with that AmountUpgraded variable, check to see if its value is correct when running the game.

2 Likes

The amount upgraded value shouldn’t be the problem. This script was working before I made it check the player’s coins.

I guess just check if the player’s coins value is correct or check if leaderstats exist? I thought you said the “amountupgraded.value == #” conditions weren’t printing anything though

This is a localscript if that has anything to do with it.

Do any errors print out in the output?

1 Like

No, there are no errors in the output.

1 Like

By the way what do you mean by it doesn’t work?
Does the entire script not work entirely? Do your coins get deducted when you upgrade? Does the character’s speed not get modified when u use it?

1 Like

Before I made it cost coins, the speed got upgraded. Now when you click the button nothing happens. It prints “Pressed Upgrade” but apart from that, nothing.

You didn’t add an if statement for each AmountUpgraded Value
Modify anything you want yourself cause I was kinda lazy here lol

local player = game.Players.LocalPlayer
local nowalkspeed = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed
script.Parent.Text = "30 Coins"
local AmountLeft = script.Parent.Parent.AmountOfUpgrades.AmountLeft
local AmountUpgraded = script.Parent.Parent.AmountOfUpgrades.AmountUpgraded
script.Parent.Parent.AmountOfUpgrades.Text = AmountUpgraded.Value.." / "..AmountLeft.Value
script.Parent.MouseButton1Click:Connect(function()
	print("pressed upgrade")
	print(script.Parent.Parent.AmountOfUpgrades.AmountUpgraded.Value)
	script.Parent.Parent.AmountOfUpgrades.Text = AmountUpgraded.Value.." / "..AmountLeft.Value
	if AmountUpgraded.Value == 0 then
		if player:WaitForChild("leaderstats").Coins.Value >= 30 then
			player:WaitForChild("leaderstats").Coins.Value -= 30
			AmountUpgraded.Value += 1
			game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = nowalkspeed + 1
			script.Parent.Text = "50 Coins"
			print(game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed)
		else
			print(player.Name.. " doesn't have enough coins to upgrade")
			script.Parent.BackgroundColor3 = Color3.new(1, 0, 0.0156863)
			script.Parent.Text = "Not Enough Coins!!"
			task.wait(1)
			script.Parent.BackgroundColor3 = Color3.new(1, 0.85098, 0)
			script.Parent.Text = "50 Coins"
		end
	elseif AmountUpgraded.Value == 1 then
		if player:WaitForChild("leaderstats").Coins.Value >= 30 then
			player:WaitForChild("leaderstats").Coins.Value -= 30
			AmountUpgraded.Value += 1
			game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = nowalkspeed + 3
			script.Parent.Text = "50 Coins"
			print(game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed)
		else
			print(player.Name.. " doesn't have enough coins to upgrade")
			script.Parent.BackgroundColor3 = Color3.new(1, 0, 0.0156863)
			script.Parent.Text = "Not Enough Coins!!"
			task.wait(1)
			script.Parent.BackgroundColor3 = Color3.new(1, 0.85098, 0)
			script.Parent.Text = "50 Coins"
		end
	elseif AmountUpgraded.Value == 2 then
		if player:WaitForChild("leaderstats").Coins.Value >= 30 then
			player:WaitForChild("leaderstats").Coins.Value -= 30
			AmountUpgraded.Value += 1
			game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = nowalkspeed + 5
			script.Parent.Text = "50 Coins"
			print(game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed)
		else
			print(player.Name.. " doesn't have enough coins to upgrade")
			script.Parent.BackgroundColor3 = Color3.new(1, 0, 0.0156863)
			script.Parent.Text = "Not Enough Coins!!"
			task.wait(1)
			script.Parent.BackgroundColor3 = Color3.new(1, 0.85098, 0)
			script.Parent.Text = "50 Coins"
		end
	elseif AmountUpgraded.Value == 3 then
		if player:WaitForChild("leaderstats").Coins.Value >= 50 then
			player:WaitForChild("leaderstats").Coins.Value -= 50
			AmountUpgraded.Value += 1
			game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = nowalkspeed + 10
			script.Parent.Text = "100 Coins"
			print(game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed)
		else
			print(player.Name.. " doesn't have enough coins to upgrade")
			script.Parent.BackgroundColor3 = Color3.new(1, 0, 0.0156863)
			script.Parent.Text = "Not Enough Coins!!"
			task.wait(1)
			script.Parent.BackgroundColor3 = Color3.new(1, 0.85098, 0)
			script.Parent.Text = "100 Coins"
		end
	elseif AmountUpgraded.Value == 4 then
		if player:WaitForChild("leaderstats").Coins.Value >= 100 then
			player:WaitForChild("leaderstats").Coins.Value -= 100
			AmountUpgraded.Value += 1
			game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = nowalkspeed + 15
			script.Parent.Text = "150 Coins"
			print(game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed)
		else
			print(player.Name.. " doesn't have enough coins to upgrade")
			script.Parent.BackgroundColor3 = Color3.new(1, 0, 0.0156863)
			script.Parent.Text = "Not Enough Coins!!"
			task.wait(1)
			script.Parent.BackgroundColor3 = Color3.new(1, 0.85098, 0)
			script.Parent.Text = "150 Coins"
		end
	elseif AmountUpgraded.Value == 5 then
		if player:WaitForChild("leaderstats").Coins.Value >= 150 then
			player:WaitForChild("leaderstats").Coins.Value -= 150
			AmountUpgraded.Value += 1
			game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = nowalkspeed + 20
			script.Parent.Text = "200 Coins"
			AmountUpgraded.Value = AmountUpgraded.Value + 1
			print(game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed)
		else
			print(player.Name.. " doesn't have enough coins to upgrade")
			script.Parent.BackgroundColor3 = Color3.new(1, 0, 0.0156863)
			script.Parent.Text = "Not Enough Coins!!"
			task.wait(1)
			script.Parent.BackgroundColor3 = Color3.new(1, 0.85098, 0)
			script.Parent.Text = "200 Coins"
		end
	elseif AmountUpgraded.Value == 6 then
		if player:WaitForChild("leaderstats").Coins.Value >= 200 then
			player:WaitForChild("leaderstats").Coins.Value -= 200
			AmountUpgraded.Value += 1
			game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = nowalkspeed + 25
			script.Parent.Text = "250 Coins"
			AmountUpgraded.Value = AmountUpgraded.Value + 1
			print(game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed)
		else
			print(player.Name.. " doesn't have enough coins to upgrade")
			script.Parent.BackgroundColor3 = Color3.new(1, 0, 0.0156863)
			script.Parent.Text = "Not Enough Coins!!"
			task.wait(1)
			script.Parent.BackgroundColor3 = Color3.new(1, 0.85098, 0)
			script.Parent.Text = "250 Coins"
		end
	elseif AmountUpgraded.Value == 7 then
		if player:WaitForChild("leaderstats").Coins.Value >= 250 then
			player:WaitForChild("leaderstats").Coins.Value -= 250
			AmountUpgraded.Value += 1
			game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = nowalkspeed + 30
			script.Parent.Text = "300 Coins"
			print(game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed)
		else
			print(player.Name.. " doesn't have enough coins to upgrade")
			script.Parent.BackgroundColor3 = Color3.new(1, 0, 0.0156863)
			script.Parent.Text = "Not Enough Coins!!"
			task.wait(1)
			script.Parent.BackgroundColor3 = Color3.new(1, 0.85098, 0)
			script.Parent.Text = "300 Coins"
		end
	elseif AmountUpgraded.Value == 8 then
		if player:WaitForChild("leaderstats").Coins.Value >= 300 then
			player:WaitForChild("leaderstats").Coins.Value -= 300
			AmountUpgraded.Value += 1
			game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = nowalkspeed + 35
			script.Parent.Text = "350 Coins"
			print(game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed)
		else
			print(player.Name.. " doesn't have enough coins to upgrade")
			script.Parent.BackgroundColor3 = Color3.new(1, 0, 0.0156863)
			script.Parent.Text = "Not Enough Coins!!"
			task.wait(1)
			script.Parent.BackgroundColor3 = Color3.new(1, 0.85098, 0)
			script.Parent.Text = "350 Coins"
		end
	elseif AmountUpgraded.Value == 9 then
		if player:WaitForChild("leaderstats").Coins.Value >= 350 then
			player:WaitForChild("leaderstats").Coins.Value -= 350
			AmountUpgraded.Value += 1
			game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = nowalkspeed + 40
			script.Parent.Text = "400 Coins"
			print(game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed)
		else
			print(player.Name.. " doesn't have enough coins to upgrade")
			script.Parent.BackgroundColor3 = Color3.new(1, 0, 0.0156863)
			script.Parent.Text = "Not Enough Coins!!"
			task.wait(1)
			script.Parent.BackgroundColor3 = Color3.new(1, 0.85098, 0)
			script.Parent.Text = "400 Coins"
		end
	elseif AmountUpgraded.Value >= 10 then
		if player:WaitForChild("leaderstats").Coins.Value >= 400 then
			player:WaitForChild("leaderstats").Coins.Value -= 400
			game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = nowalkspeed + 50
			script.Parent.Text = "MAXED"
			print(game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed)
		else
			print(player.Name.. " doesn't have enough coins to upgrade")
			script.Parent.BackgroundColor3 = Color3.new(1, 0, 0.0156863)
			script.Parent.Text = "Not Enough Coins!!"
			task.wait(1)
			script.Parent.BackgroundColor3 = Color3.new(1, 0.85098, 0)
			script.Parent.Text = "MAXED"
		end
	end
end)
1 Like

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