Hi. So I have made this speed upgrade shop and it’s all going pretty well, but how would I make it save? As of now, it removes coins from the player and boosts their speed. How can I make their speed save? Here is the script and I just wouldn’t know where to start with this so thanks to anyone who even attempts to help!
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)