So me and my friend are working on a game and we are running into a problem with our car shop GUI not saving. We are trying to make it so that when you purchase a car, it will save it and when you join, it loads all of your stats. I have also tried using a remote event, but I cannot figure out how to use it.
Here is some of our car spawn code and purchase code if it will help.
Spawn code.
game.ReplicatedStorage:WaitForChild("CheckPrice").OnServerInvoke = function(player,NameOfCar)
return game.ServerStorage.Cars:FindFirstChild(NameOfCar).Price.Value
end
game.ReplicatedStorage:WaitForChild("SpawnCar").OnServerEvent:Connect(function(player,NameOfCar)
local car = game.ServerStorage.Cars:FindFirstChild(NameOfCar):Clone()
car:SetPrimaryPartCFrame(player.Character.HumanoidRootPart.CFrame + Vector3.new(0,0,15))
car.Parent = workspace
car:MakeJoints()
car.Name = player.Name.."'s "..NameOfCar
end)
Purchase code.
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Parent.Purchased.Value == true then
-- Spawn it
game.ReplicatedStorage.SpawnCar:FireServer(script.Parent.Parent.Name)
else
-- Let them purchase it
local PriceOfItem = game.ReplicatedStorage:WaitForChild("CheckPrice"):InvokeServer(script.Parent.Parent.Name)
if game.Players.LocalPlayer.leaderstats.Cash.Value >= PriceOfItem and script.Parent.Parent.Purchased.Value == false then
-- The player has enough cash
game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value - PriceOfItem
script.Parent.Parent.Purchased.Value = true
script.Parent.Text = "Spawn"
script.Parent.MouseButton1Click:connect(function()
-- Deletes the car if there are multiple.
for i,v in pairs(game.Workspace:GetChildren()) do
if v.Name == game.Players.LocalPlayer.Name.."'s 1983 Yokoza Runner Rapid GT 2-Door (AA86)" then
v:Destroy()
end
end
end)
end
end
end)
Here is the link to the game as well
Any help is greatly appreciated.
