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

How would I turn my data store script into a data store script using remote events? [closed]

Asked by 5 years ago

Hi, I have a datastore script that works like its suppose to, but when I click a gui that gives me money it doesnt save. I saw that you have to use remote events to do stuff with local scripts, when filtering is on. I dont know how to use remote events and need help. I cant find any tutorials of how to do it. This is my datastore script, how would I put remote events to use in it?

local DataStoreService = game:GetService("DataStoreService")



local myDataStore = DataStoreService:GetDataStore("myDataStore")

local myDataStore2 = DataStoreService:GetDataStore("myDataStore")



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

local leaderstats = Instance.new("Folder")

leaderstats.Name = "leaderstats"

leaderstats.Parent = player



local other = Instance.new("Folder")

other.Name = "other"

other.Parent = player



local money = Instance.new("IntValue")

money.Name = "Money"

money.Parent = leaderstats



local ClickMoney = Instance.new("IntValue")

ClickMoney.Name = "ClickMoney"

ClickMoney.Parent = other

ClickMoney.Value = 1



local data

local data2

local success, errormessage = pcall(function()

data = myDataStore:GetAsync(player.UserId.."-Money")

data2 = myDataStore2:GetAsync(player.UserId.."-ClickMoney")



end)



if success then

money.Value = data

ClickMoney.Value = data2

else

print("There Was An Error While Getting Your Data")

warn(errormessage)

end

end)



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

local success, errormessage = pcall (function()

myDataStore:SetAsync(player.UserId.."-Money",player.leaderstats.Money.Value)

myDataStore2:SetAsync(player.UserId.."-ClickMoney",player.other.ClickMoney.Value)

end)

if success then

print("Player Data Successfully Saved!")

else

print ("There Was An Error When Saving Data")

warn (errormessage)

end

end)

Closed as Non-Descriptive by User#24403

This question has been closed because its title or content does not adequately describe the problem you are trying to solve.
Please ensure that your question pertains to your actual problem, rather than your attempted solution. That is, you were trying to solve problem X, and you thought solution Y would work, but instead of asking about X when you ran into trouble, you asked about Y.

Why was this question closed?