Hello everyone,
Im trying to use DataStore2, for that I created everything to store etc...
Then I want that when the player joins he receives his money but locally. So I used a OnClientEvent but is it for me impossible to get back the value of money. Here is my code, Server Sided :
local players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local datastore2 = require(1936396537)
local defaultmoney = 50
players.PlayerAdded:Connect(function(player)
local MoneyStore = datastore2("Money", player)
local function updateClientMoney(amount)
replicatedStorage.RemoteEvents.UpdateMoney:FireClient(player, amount)
end
updateClientMoney(MoneyStore:Get(defaultmoney))
MoneyStore:OnUpdate(updateClientMoney)
end)
And here is my code , Client Sided:
local moneyevent = game:GetService("ReplicatedStorage").RemoteEvents.UpdateMoney
local money
moneyevent.OnClientEvent:Connect(function(amount)
print(amount)
money = amount
end)
print(money)
But when I do that i got nil for print(money). To ensure that the event is correctly fired I put also a print(amount) which works.
I got another question which I still don't found the solution. Let's imagine that I have 10 part in workspace and that I want to make a variable shortcut for each of them, so we can do the following code :
local part1 = game.workspace.part1
local part2 = game.workspace.part2
local part3 = game.workspace.part3
and etc...
But I was wondering if we can do something like that :
for x = 1,11 do
local part"x" = game.workspace.part"x"
but of course that didn't work, so I was looking to know if is possible to "include" the "x" into this for loop to get the same things as writing all variable shortcut one by one ?
Thank's in advance. Have a nice day.
