Hi, their is probably a really easy solution to this, but I’ve been stuck on this segment of code for a while that throws the error “attempt to call a number value.”
game.ReplicatedStorage.."ClientEuros"..Player.UserId"".Value)
Please help.
Hi, their is probably a really easy solution to this, but I’ve been stuck on this segment of code for a while that throws the error “attempt to call a number value.”
game.ReplicatedStorage.."ClientEuros"..Player.UserId"".Value)
Please help.
Remove the "" after Player.UserId. Also you can’t concatenate Instances.
Perhaps you meant:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local euros = ReplicatedStorage:FindFirstChild("ClientEuros" .. player.UserId)
if euros then
-- do something with euros.Value
end
Well yes, but no… its ment to be in the parentheses I ment to give the full line but I only highlighted a a bit, here…
PlayerEuros:SetAsync(Player.UserId.."Val",game.ReplicatedStorage.."ClientEuros"..Player.UserId"".Value)
So you would do
PlayerEuros:SetAsync(Player.UserId .. "Val", euros.Value)
“ClientEuros”…Player.UserId"" Is the name, since its replicated when the player joins…
But you are trying to concatenate the ReplicatedStorage service with this string. Does the player have a “ClientEuros” value in ReplicatedStorage with their username in it?
Its the name of a int value. Client euros is the intvalue upon replication with the players id.
So then I am correct, and my reply solves your problem.
No… because its trying to find the replicated int value, not the pre existing one.
PlayerEuros:SetAsync(Player.UserId.."Val", game.ReplicatedStorage["ClientEuros"][tostring(Player.UserId)].Value)
Not sure what you are trying to do… can you post the entire script
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataStorage = game:GetService("DataStoreService")
local PlayerEuros = DataStorage:GetDataStore("PlayersEuros")
Players.PlayerAdded:Connect(function(Player)
local val = ReplicatedStorage.ClientEuros:Clone()
val.Name = "ClientEuros"..Player.UserId..""
val.Parent = game.ReplicatedStorage
print(val.Name.." has been created!")
local PlayerData
local success, failure = pcall(function()
PlayerData = PlayerEuros:GetAsync(Player.UserId.."Val")
end)
if success then
val.Value = PlayerData
print("Player_"..Player.UserId.." data has been found, no worries...")
else
warn("An error has occured when loading Player_"..Player.UserId.." data, be bo beep: "..failure.."")
end
while true do
wait(1)
game.ReplicatedStorage:FindFirstChild("ClientEuros"..Player.UserId.."").Value = game.ReplicatedStorage:FindFirstChild("ClientEuros"..Player.UserId.."").Value +1
end
end)
Players.PlayerRemoving:Connect(function(Player)
local success, failure = pcall(function()
PlayerEuros:SetAsync(Player.UserId.."Val",game.ReplicatedStorage.."ClientEuros"..Player.UserId"".Value)
game.ReplicatedStorage:FindFirstChild("ClientEuros"..Player.UserId..""):Destroy()
print(Player.Name.." has left")
end)
if success then
print("Player_"..Player.UserId.." data has been saved, no worries...")
else
warn("Failure in saving Player_"..Player.UserId.." data, Running error be bo beep: "..failure.."")
end
end)
Not sure what you mean? Could you clarify? Based on the code shown, I indeed solved the problem.
(btw you don’t need to concatenate the ID with an empty string)
Try something like this instead
local PlayerStorage = Instance.new("Folder", game.ServerStorage)
PlayerStorage.Name = "PlayerStorage"
local EurosDatastore = game:GetService("DataStoreService"):GetDataStore("Euros")
local function SaveEuros(Player)
local Found = nil
local success, err
for i,v in pairs(PlayerStorage:GetChildren()) do
if v == Player.UserId then
Found = v
end
end
if Found ~= nil then
local Euros = Found.Euros
if Euros == nil then return false end
local attempts = 0
repeat
attempts += 1
success, err = pcall(function()
EurosDatastore:SaveAsync(tostring(Player.UserId), Euros.Value)
end)
until
success == true or attempts > 3
warn(err)
return success
end
end
local function LoadEuros(Player)
local Found = nil
local success, err
for i,v in pairs(PlayerStorage:GetChildren()) do
if v == Player.UserId then
Found = v
end
end
if Found ~= nil then
local Euros = Found.Euros
if Euros == nil then return false end
local attempts = 0
repeat
attempts += 1
success, err = pcall(function()
Euros.Value = EurosDatastore:GetAsync(tostring(Player.UserId)) or 0
end)
until
success == true or attempts > 3
warn(err)
return success
end
end
game.Players.PlayerAdded:Connect(function(Player)
local Found = nil
for i,v in pairs(PlayerStorage:GetChildren()) do
if v == Player.UserId then
Found = v
end
end
if Found == nil then
local PlayerFolder = Instance.new("Folder", PlayerStorage)
PlayerFolder.Name = tostring(Player.UserId)
local Euros = Instance.new("NumberValue", PlayerFolder)
Euros.Name = "Euros"
end
LoadEuros(Player)
end)
game.Players.PlayerRemoving:Connect(function(Player)
for i,v in pairs(PlayerStorage:GetChildren()) do
if v.Name == Player.UserId then
repeat
wait()
until
SaveEuros(Player) ~= nil
v:Destroy()
end
end
end)
Even though I didn’t use your script , because that would be unoringinal of me, I’m gonna mark it right. I revised my own script now, so it now works.