Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

error: GetAsync is not a valid member of IntValue i dont know what to do?

my script is

local Total  = game:GetService("DataStoreService"):GetDataStore("Total")

function savedata(dataname, playerid, value)
	game:GetService("DataStoreService"):GetDataStore(dataname):SetAsync(playerid, value)
end

game.Players.PlayerAdded:connect(function(player)
	local swordfolder = Instance.new('Folder')
	swordfolder.Name = 'Swords'
	swordfolder.Parent = player
	local Total = Instance.new('IntValue')
	Total.Value = Total:GetAsync(tostring(player.userId))
	Total.Parent = game.Players.LocalPlayer
	Total.Name = 'TotalSwordValue'
	
	Total.Changed:connect(function()
		savedata("Total", player.userId, Total.Value)
	end)
	savedata("Total", player.userId, Total.Value)
end)

game.Players.PlayerRemoving:connect(function(player)
	savedata("Total", player.userId, player.Total.Value)
end)

error in the title the line is 12

1 answer

✓ Accepted answer

When you create the local Total variable which references the IntValue, it "overrides", if you will, the above Total variable which references your DataStore. You can remedy this by changing the name of the second variable:

local Total  = game:GetService("DataStoreService"):GetDataStore("Total")

function savedata(dataname, playerid, value)
    game:GetService("DataStoreService"):GetDataStore(dataname):SetAsync(playerid, value)
end

game.Players.PlayerAdded:connect(function(player)
    local swordfolder = Instance.new('Folder')
    swordfolder.Name = 'Swords'
    swordfolder.Parent = player
    local TotalVal = Instance.new('IntValue')
    TotalVal.Value = Total:GetAsync(tostring(player.UserId)) --// userId is deprecated, use UserId instead.
    TotalVal.Parent = game.Players.LocalPlayer
    TotalVal.Name = 'TotalSwordValue'

    TotalVal.Changed:connect(function()
        savedata("Total", player.UserId, TotalVal.Value)
    end)
    savedata("Total", player.UserId, TotalVal.Value)
end)

game.Players.PlayerRemoving:connect(function(player)
    savedata("Total", player.UserId, player.Total.Value) --// You've named the IntValue "TotalSwordValue" but index "Total" here; may want to fix that as well.
end)

Hope this helped.

1 comment

0

thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.