You can use your coins to buy upgrades, and I have remote events set up to give you those upgrades AND take away the coins. Once bought it doesn't take away the coins OR give you the upgrade, but the script continues like everything worked. (I know this because it destroys the button after purchase)
Server-Side Script (For all remote events)
local replicatedStorage = game:GetService("ReplicatedStorage") replicatedStorage.RemoteControl.RemoteJumpCoin.OnServerEvent:connect(function(player, datatype) if datatype == "AddJump" then local JumpAmount = Instance.new("IntValue", game:GetService("ServerStorage")) JumpAmount.Name = player.Name.."Jumps" JumpAmount.Value = 1 player.Name.leaderstats.Coins.Value = player.Name.leaderstats.Coins.Value + JumpAmount end end) replicatedStorage.RemoteControl.Upgrades.OnServerEvent:connect(function(player, upgrade) if upgrade == "Velocity" then local trampoline = game.Workspace.Trampoline local trampVel = trampoline.Velocity local velval = game:GetService("ServerStorage"):FindFirstChild("VelVal") for i,v in pairs(game:GetService("ServerStorage"):FindFirstChild(player.Name)) do if v:IsA("Folder") then for i,vel in pairs(v:FindFirstChild("Velocity")) do if vel:IsA("Vector3Value") then vel.Value = Vector3.new(0, velval.Value + 20, 0) end end end end elseif upgrade == "JumpConvert" then -- To Be Added Later elseif upgrade == "MoreJumps" then local JumpAmount = game:GetService("ServerStorage"):FindFirstChild(player.Name.."Jumps") JumpAmount = JumpAmount.Value + 1 end end) replicatedStorage.RemoteControl.PurchaseUpgrade.OnServerEvent:connect(function(player, upgrade) if upgrade == "Jump1" then player.Name.leaderstats.Coins.Value = player.Name.leaderstats.Coins.Value - 200 elseif upgrade == "Jump2" then player.Name.leaderstats.Coins.Value = player.Name.leaderstats.Coins.Value - 500 elseif upgrade == "Jump3" then player.Name.leaderstats.Coins.Value = player.Name.leaderstats.Coins.Value - 1000 elseif upgrade == "Jump4" then player.Name.leaderstats.Coins.Value = player.Name.leaderstats.Coins.Value - 1700 end end) replicatedStorage.RemoteControl.PurchaseVel.OnServerEvent:connect(function(player, upgrade) if upgrade == "Vel1" then player.Name.leaderstats.Coins.Value = player.Name.leaderstats.Coins.Value - 100 elseif upgrade == "Vel2" then player.Name.leaderstats.Coins.Value = player.Name.leaderstats.Coins.Value - 300 elseif upgrade == "Vel3" then player.Name.leaderstats.Coins.Value = player.Name.leaderstats.Coins.Value - 650 elseif upgrade == "Vel4" then player.Name.leaderstats.Coins.Value = player.Name.leaderstats.Coins.Value - 1300 end end)
Here is where I "FireServer" to connect to these events (the events are held in ReplicatedStorage within a script)
Client-Side Connections
local player = game.Players.LocalPlayer local ui = player:WaitForChild("PlayerGui") local gameUi = ui:WaitForChild("Game") local replicatedStorage = game:GetService("ReplicatedStorage") local serverStorage = game:GetService("ServerStorage") local remoteControl = replicatedStorage.RemoteControl local upgradesRem = remoteControl.Upgrades local purchaseUpg = remoteControl.PurchaseUpgrade local purchaseVel = remoteControl.PurchaseVel local jumps = player.leaderstats.Jumps local coins = player.leaderstats.Coins local velocity = replicatedStorage:WaitForChild(player.Name).Velocity local velStorage = replicatedStorage.Velocity:FindFirstChild(player.Name) local upgrades = gameUi.UpgradesF local vel = upgrades.Velocity local jum = upgrades.Jumps local jumpAmount = serverStorage:FindFirstChild(player.Name.."Jumps") local jumPurchased = false local jumPurchased2 = false local jumPurchased3 = false local jumPurchased4 = false local velPurchased = false local velPurchased2 = false local velPurchased3 = false local velPurchased4 = false for i,v in pairs(jum:GetChildren()) do if v:IsA("TextButton") then if v.Name == "MoreJumps" then v.MouseButton1Click:connect(function(onClicked) if coins.Value >= 200 then if jumPurchased == false then jumPurchased = true purchaseUpg:FireServer(player, "Jump1") wait(0.05) upgradesRem:FireServer(player, "MoreJumps") v:Destroy() end end end) elseif v.Name == "MoreJumps2" then v.MouseButton1Click:connect(function(onClicked) if coins.Value >= 500 then if jumPurchased2 == false then jumPurchased2 = true purchaseUpg:FireServer(player, "Jump2") wait(0.05) upgradesRem:FireServer(player, "MoreJumps") v:Destroy() end end end) elseif v.Name == "MoreJumps3" then v.MouseButton1Click:connect(function(onClicked) if coins.Value >= 1000 then if jumPurchased3 == false then jumPurchased3 = true purchaseUpg:FireServer(player, "Jump3") wait(0.05) upgradesRem:FireServer(player, "MoreJumps") v:Destroy() end end end) elseif v.Name == "MoreJumps4" then v.MouseButton1Click:connect(function(onClicked) if coins.Value >= 1700 then if jumPurchased4 == false then jumPurchased4 = true purchaseUpg:FireServer(player, "Jump4") wait(0.05) upgradesRem:FireServer(player, "MoreJumps") v:Destroy() end end end) end end end for i,v in pairs(vel:GetChildren()) do if v:IsA("TextButton") then if v.Name == "MoreVelocity" then v.MouseButton1Click:connect(function(onClicked) if coins.Value >= 100 then if velPurchased == false then velPurchased = true purchaseVel:FireServer(player, "Vel1") wait(0.05) upgradesRem:FireServer(player, "Velocity") v:Destroy() end end end) elseif v.Name == "MoreVelocity2" then v.MouseButton1Click:connect(function(onClicked) if coins.Value >= 300 then if velPurchased2 == false then velPurchased2 = true purchaseVel:FireServer(player, "Vel2") wait(0.05) upgradesRem:FireServer(player, "Velocity") v:Destroy() end end end) elseif v.Name == "MoreVelocity3" then v.MouseButton1Click:connect(function(onClicked) if coins.Value >= 650 then if velPurchased3 == false then velPurchased3 = true purchaseVel:FireServer(player, "Vel3") wait(0.05) upgradesRem:FireServer(player, "Velocity") v:Destroy() end end end) elseif v.Name == "MoreVelocity4" then v.MouseButton1Click:connect(function(onClicked) if coins.Value >= 1300 then if velPurchased4 == false then velPurchased4 = true purchaseVel:FireServer(player, "Vel4") wait(0.05) upgradesRem:FireServer(player, "Velocity") v:Destroy() end end end) end end end