NotZylon
(shiesty)
March 7, 2021, 3:36pm
#1
So im using datastore2 and i tried putting in a local script inside a text label but it’s like the script isn’t there. It doesn’t make any changes or anything, how do i fix this?
local replicatedStorage = game:GetService("ReplicatedStorage")
replicatedStorage.RemoteEvents.UpdateClientCurrency.OnClientEvent:Connect(function(amount)
script.Parent.Text = "$" .. amount
end)
1 Like
You’ll have to us the code that is trying to activate this RemoteEvent since there doesn’t seem to be any issue here besides that if amount is always going to be a number, you should make amount a string
script.Parent.Text = "$" .. tostring(amount)
NotZylon
(shiesty)
March 7, 2021, 3:43pm
#3
doesn’t work it does the same thing, it doesn’t make updates
Then you’ll have to show the code that actually fires the Event
Proscled
(Proscled)
March 7, 2021, 3:46pm
#5
Hi, you should try printing if the event actually gets fired at all. If it doesn’t print anything there is something wrong with the script firing the event.
NotZylon
(shiesty)
March 7, 2021, 3:47pm
#6
here
local function updateClientCurrency(amount)
replicatedStorage.Events.UpdateClientCurrency:FireClient(player, amount)
end
updateClientCurrency(CurrencyStore:Get(DefaultCurrencyAmount))
CurrencyStore:OnUpdate(updateClientCurrency)
NotZylon
(shiesty)
March 7, 2021, 3:48pm
#7
oh, i added prints and nothing printed
Is the function even being called? Add a print inside it
Proscled
(Proscled)
March 7, 2021, 3:49pm
#9
Yeah, there could be something wrong with the function itself. It looks fine in my eyes tho.
NotZylon
(shiesty)
March 7, 2021, 3:49pm
#10
i added a print in the function and nothing happened
Proscled
(Proscled)
March 7, 2021, 3:50pm
#11
There’s something wrong with the ‘CurrencyStore’ module probably. That’s the only clue I got right now.
NotZylon
(shiesty)
March 7, 2021, 3:51pm
#12
Everything is saving correctly it’s just that the gui is not showing
local DataStore2 = require(ServerStorage:WaitForChild("DataStore2"))
local CurrencyStore = DataStore2("Currency", player)
Proscled
(Proscled)
March 7, 2021, 3:52pm
#13
Is the ‘:OnUpdate()’ function working correctly? Try printing there.
NotZylon
(shiesty)
March 7, 2021, 3:53pm
#14
local function updateClientCurrency(amount)
replicatedStorage.Events.UpdateClientCurrency:FireClient(player, amount)
print("Cool")
end
updateClientCurrency(CurrencyStore:Get(DefaultCurrencyAmount))
CurrencyStore:OnUpdate(updateClientCurrency)
Nothing happened
Proscled
(Proscled)
March 7, 2021, 3:54pm
#15
Show the code of the module to us.
NotZylon
(shiesty)
March 7, 2021, 3:54pm
#16
heres the whole code
local replicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
local DataStore2 = require(ServerStorage:WaitForChild("DataStore2"))
local DefaultCurrencyAmount = 1
game.Players.PlayerAdded:Connect(function(player)
local InventoryStore = DataStore2("Inventory", player)
local CurrencyStore = DataStore2("Currency", player)
local replicatedDataFolder = Instance.new("Folder")
replicatedDataFolder.Parent = replicatedStorage.ReplicatedData
replicatedDataFolder.Name = player.UserId
local inventoryString = Instance.new("StringValue")
inventoryString.Parent = replicatedDataFolder
inventoryString.Name = "Inventory"
local inventoryData = InventoryStore:Get({})
inventoryString.Value = HttpService:JSONEncode(inventoryData)
InventoryStore:OnUpdate(function(decodedData)
inventoryString.Value = HttpService:JSONEncode(decodedData)
local function updateClientCurrency(amount)
replicatedStorage.Events.UpdateClientCurrency:FireClient(player, amount)
print("Cool")
end
updateClientCurrency(CurrencyStore:Get(DefaultCurrencyAmount))
CurrencyStore:OnUpdate(updateClientCurrency)
print("Again")
end)
end)
game.Workspace:WaitForChild("Bruh").ClickDetector.MouseClick:Connect(function(player)
local CurrencyStore = DataStore2("Currency", player)
CurrencyStore:Increment(50,DefaultCurrencyAmount)
end)
Proscled
(Proscled)
March 7, 2021, 3:56pm
#17
It prints nothing of these? That’s very weird… I don’t see the solution though. Never used Datastores2 though.
local DataStore2 = require(ServerStorage:WaitForChild("DataStore2"))
DataStore2.Combine("DATA", "Inventory", "Currency")
I think you forgot to do this, it’s required you combine all your data fields like this for it to work
After declaring the DataStore2 Variable, add the 2nd line afterwards