Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My script that gives money messes up purchasing cars? [closed]

Asked by 6 years ago

Okay, so here we go. I have a leader board and add money script. The add money script does work until my GUI that spawns cars comes in. So you buy cars for money, and the money you can get from +5ing every few seconds. Lets say I get enough cash to buy a car. I buy it, then lose the money I used to purchase, few seconds later my +5 script adds more money, but heres the catch. It glitches and adds to the old amount of money, not the new amount.

Code Blocks --

+5 Script thing ---

amount = 2 -- This variable is the amount of cash we will give each time.
timedelay = 2 -- This variable is the amount of seconds inbetween each time the cash is rewarded
currencyname = "Cash" -- This is the name of our Currency

while true do
    wait(timedelay)
    for i,v in pairs(game.Players:GetPlayers()) do
        if v:FindFirstChild("leaderstats") and v then
            v.leaderstats[currencyname].Value = v.leaderstats[currencyname].Value + amount
        end
    end
end

Leaderstats thing

local DSService = game:GetService('DataStoreService'):GetDataStore('Car00071isaproatscripting10202')
game.Players.PlayerAdded:connect(function(plr)
    -- Define variables
    local uniquekey = 'id-'..plr.userId
    local leaderstats = Instance.new('IntValue', plr)
    local savevalue =  Instance.new('IntValue')
    leaderstats.Name = 'leaderstats'
    savevalue.Parent = leaderstats
    savevalue.Name = 'Cash'

    savevalue.Value = DSService:GetAsync(plr.UserId) or 0
    DSService:SetAsync(plr.UserId, savevalue.Value)

    -- GetAsync
    local GetSaved = DSService:GetAsync(uniquekey)
    if GetSaved then
        savevalue.Value = GetSaved[1]
    else
        local NumbersForSaving = {savevalue.Value}
        DSService:SetAsync(uniquekey, NumbersForSaving)
    end
end)

game.Players.PlayerAdded:connect(function(plr)

game.Players.plr.leaderstats.Cash.Value.Changed:connect(function()
    local uniquekey = 'id-'..plr.userId
    local leaderstats = Instance.new('IntValue', plr)
    local savevalue =  Instance.new('IntValue')
    local Savetable = {plr.leaderstats.Cash.Value}
    DSService:SetAsync(uniquekey, Savetable)
end)
end)

game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local Savetable = {plr.leaderstats.Cash.Value}
DSService:SetAsync(uniquekey, Savetable)    



end)

game.ReplicatedStorage:WaitForChild("SpawnCar").OnServerEvent:Connect(function(plr)
    local uniquekey = 'id-'..plr.userId
local Savetable = {plr.leaderstats.Cash.Value}
DSService:SetAsync(uniquekey, Savetable)    

end)

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.PrimaryPart = car.Chassis
car:SetPrimaryPartCFrame(player.Character.HumanoidRootPart.CFrame + Vector3.new(0,0,15))
car.Parent = workspace
car:MakeJoints()
car.Name = player.Name.."'s "..NameOfCar
end)


Please, help me.

Thanks, Car00071. Discord -- Car00071#6837

0
Don’t come on this site with alvinbloxx’s code, expecting for it to be fixed. User#19524 175 — 6y

Closed as Not Constructive by User#19524

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?