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

My DataStore script won't save/load?

Asked by
markjac -11
6 years ago

My DataStore script won't save or maybe won't load players data. I have a button in game that raises the values of GoldRubyC and CollectionValue

01local datastore = game:GetService("DataStoreService"):GetDataStore("tablohazerjia1")
02 
03 
04game.Players.PlayerAdded:connect(function(player)
05        local PlayerProfile = Instance.new("Folder")
06    PlayerProfile.Name = "PlayerProfile"
07    PlayerProfile.Parent = player
08 
09 
10    -------------------- [Collected Treasure Verified]-
11    local TreasuresCollected = Instance.new("IntValue")
12    TreasuresCollected.Name = "TreasuresCollected"
13    TreasuresCollected.Parent = PlayerProfile
14    ---------------------------------------------------
15 
View all 51 lines...
0
Go into your game through your profile, go into the command page and give yourself these values, tell me if they save when you do it that way Hizar7 102 — 6y

1 answer

Log in to vote
0
Answered by
Hizar7 102
6 years ago

Hi mark, the problem is you're trying to get the values through a local script. you're going to need to use a server script. Use a remote Event from the local script to tell the server script to add the points, ill demonstrate here. Put a RemoteEvent inside the ReplicatedStorage, its an addable item through right click options. then put this into the local script after the button has been pressed.

1game.ReplicatedStorage.RemoteEvent:FireServer()

then add this to a server script

1game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr)

then add underneath that line to add the values to the folder. like this

1local myName = "TreasuresCollected"
2game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr)
3 
4local TreasuresCollected = plr.PlayerProfile:FindFirstChild(myName)
5      TreasuresCollected.Value =TreasuresCollected.Value + 1
6end)

let me know if this works!

0
if this works please accept this answer, I'd appreciate it ! Hizar7 102 — 6y
Ad

Answer this question