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

Incomplete statement: expected assignment or a function call obby?

Asked by 4 years ago
Edited by Ziffixture 4 years ago
local DataStoreService = game:GetService("DataStoreService")

local myDataStore = DataStoreService:GetDataStore("MyDataStore")

game.Players.PlayerAdded:connect(function(player)
 local leaderstats = Instance.new("Folder")
 leaderstats.Name = "leaderstats"
 leaderstats.Parent= player

 local stage = Instance.new("IntValue")
 stage.Name = "Stage"
 stage.Parent leaderstats
 ack2.Value = 0

 local data
 local success, errormessage = pcall(function)
    myDataStore:GetAsync(player.UserId.."")
 end)

 if success then
    stage.value = data
 else
    print("There was an error whilst getting your data")
    warn(errormessage)
 end
end)

game.Players.PlayerRemoving:Connect(function(player)

 local success, errormessage = pcall(function)
    myDataStore:SetAsync(player.UserId.."stage",player.leaderstats.Stage.Value)
    end)

    if success then
        print("Player Data successufully saved!")
    else
        print("There was an error when saving data")
        warn(errormessage)
    end
end)

 stage.Value = ds1:GetAsync(plr.UserId) or 1
 ds1:SetAsync(plr.UserId, stage.Value)

 stage.Changed:connect(function()
  ds1:SetAsync(plr.UserId, stage.Value)
 end)
end)

0
Give it one last shot, something slipped under my fnigers! Ziffixture 6913 — 4y
0
no is still not working thestorm2897 10 — 4y
0
But thank you for your help! thestorm2897 10 — 4y

1 answer

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

Your program contained syntax errors on lines 16-18. You also had several logic issues with you Script which were going to run you into a cesspool of semantic errors too. Please be careful when writing code.

Note:

It is also highly recommended not to to make :SetAsync() calls every time the ValueObject updates. You put your DataStore at high-risk for exhaustion problems. Since you're saving a single Value, it's not important to do so either, so just leave requests for PlayerLeaving.

You should also use :BindToClose() with DataStore's to compensate for abrupt server-shutdownts.

local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("MyDataStore")

local Players = game:GetService("Players")

Players.PlayerAdded:connect(function(Player)
    local Leaderstats = Instance.new("Folder")
    Leaderstats.Name = "leaderstats"
    Leaderstats.Parent= Player

    local Stage = Instance.new("IntValue")
    Stage.Name = "Stage"
    Stage.Value = 0
    Stage.Parent = leaderstats

    local Data;
    local Success, ErrorMessage = pcall(function()
        Data = myDataStore:GetAsync(Player.UserId.."-Stage")
    end)
    if (Success) then
        Stage.Value = Data
    else
        print("There was an error whilst getting your data!")
        warn(ErrorMessage)
    end
end)

Players.PlayerRemoving:Connect(function(Player)
    local Leaderstats = Player:FindFirstChild("Leaderstats")
    if (Leaderstats and Leaderstats.Stage) then
        local Stage = Leaderstats.Stage.Value
        local Success, ErrorMessage = pcall(function()  
            myDataStore:SetAsync(Player.UserId.."-Stage", Stage)
        end)
        if (Success) then
            print("Successfully saved data!")
        else
            print("There was an error whilst saving your data!")
            warn(ErrorMessage)
        end
    end
end)

game:BindToClose(function()
    for _,Player in pairs(Players:GetPlayers()) do
        Player:Kick() --// Force PlayerLeaving to fire
    end
end)

Remember to accept this answer if it helps!

0
Sorry there was problem between lines 37 and 41 There was an error whilst saving your data! I don't know what that could be the problem I would really appreciate your response thank you. thestorm2897 10 — 4y
0
It just says nil thestorm2897 10 — 4y
0
My apologies, a simple syntax error. The code above should be all dandy! Ziffixture 6913 — 4y
0
sorry is still says There was an error whilst saving your data nil and Success and ErrorMessage are Underlined thestorm2897 10 — 4y
View all comments (2 more)
0
Same deal again, give it a shot now! Ziffixture 6913 — 4y
0
Sorry there are no errors anymore but it wouldn't say successfully saved data and when I am at a checkpoint it would not load there the next time I log out thestorm2897 10 — 4y
Ad

Answer this question