My upgrade system is not working, please tell me what is wrong with my code.
It basically does not fire the remote event when the button is clicked.
LocalScript that fires the event
local cash = game.Players.LocalPlayer.leaderstats.Cash
local price1 = 150
local level = game.Players.LocalPlayer.upgradestats.Upgrade
local player = game.Players.LocalPlayer
local price = price1 * level.Value
while wait() do
script.Parent.Price.Text = "Price: "..price.." Cash"
script.Parent.Level.Text = "Your Level: "..level.Value
end
script.Parent.Submit.MouseButton1Click:Connect(function()
game.ReplicatedStorage.Upgrade:FireServer(player, price)
print("made it") --this part is not printing
end)
Script that is supposed to receive the event
game.ReplicatedStorage.Upgrade.OnServerEvent:Connect(function(player, price)
if player.leaderstats.Cash.Value > price - 1 then
player.leaderstats.Cash.Value -= price
player.upgradestats.Upgrade.Value += 1
end
end)
leaderstats
local service = game:GetService("DataStoreService")
local datastore = service:GetDataStore("JumpStore")
local datastore2 = service:GetDataStore("CashStore")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder", plr)
leaderstats.Name = "leaderstats"
local stat = Instance.new("IntValue", leaderstats)
stat.Name = "Jumps"
local stat2 = Instance.new("IntValue", leaderstats)
stat2.Name = "Cash"
local data
local success, errorMessage = pcall(function()
data = datastore:GetAsync(plr.UserId.."-jumps")
end)
local data2
local success2, errorMessage2 = pcall(function()
data2 = datastore2:GetAsync(plr.UserId.."-cash")
end)
if success then
stat.Value = data
else
warn(errorMessage)
end
if success2 then
stat2.Value = data2
else
warn(errorMessage2)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, errorMessage = pcall(function()
datastore:SetAsync(plr.UserId.."-jumps", plr.leaderstats.Jumps.Value)
end)
if not success then
warn(errorMessage)
end
local success2, errorMessage2 = pcall(function()
datastore2:SetAsync(plr.UserId.."-cash", plr.leaderstats.Cash.Value)
end)
if not success2 then
warn(errorMessage2)
end
end)
upgradestats (level)
local service = game:GetService("DataStoreService")
local datastore = service:GetDataStore("UpgradeStore")
game.Players.PlayerAdded:Connect(function(plr)
local upgradestats = Instance.new("Folder", plr)
upgradestats.Name = "upgradestats"
local stat = Instance.new("IntValue", upgradestats)
stat.Name = "Upgrade"
local data
local success, errorMessage = pcall(function()
data = datastore:GetAsync(plr.UserId.."-upgrade")
end)
if success then
stat.Value = data
else
warn(errorMessage)
end
if stat.Value == 0 then
stat.Value = 1
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, errorMessage = pcall(function()
datastore:SetAsync(plr.UserId.."-upgrade", plr.upgradestats.Upgrade.Value)
end)
if not success then
warn(errorMessage)
end
end)
Ty!