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

Data Store, "attempt to index number with 'fire'"?

When I did this it gave the error code of, attempt to index number with 'fire'

local DataStore = game:GetService("DataStoreService")
local mydatastore = DataStore:GetDataStore("mydatastore")-- making a datastore under the name my datastore

game.Players.PlayerAdded:Connect(function(player)
	
	local ben = Instance.new ("Folder")
	ben.Name = "ben"
	ben.Parent = player
	
	local fire = Instance.new ("IntValue")
	fire.Name = "fire"
	fire.Parent = ben
	
	local water = Instance.new("IntValue")
	water.Name = "water"
	water.Parent = ben
	
	local earth = Instance.new("IntValue")
	earth.Name = "earth"
	earth.Parent = ben
	
	local air = Instance.new("IntValue")
	air.Name = "air"
	air.Parent = ben
	
	local data -- this defines what data is we cant do it in the mid cuz its unknown global
	local playeruserid = "player"..player.UserId
	
	local success, errormessage = pcall(function() -- this finds out if the player has played the game before
	data = mydatastore:GetAsync(playeruserid) -- this will sync the data to what we have in the data store
	
	end)
	if success then
		fire.Value = data.fire
		water.Value = data.water
		earth.Value = data.earth
		air.Value = data.air
		
		    --set our data = to the current fire
	end
end)
game.Players.PlayerRemoving:Connect(function(player) -- if the player leaves this fires 
	local playeruserid = "player"..player.UserId
	
	local data = {
	fire = player.ben.fire.Value;
	water = player.ben.water.Value;
	earth = player.ben.earth.Value;
	air = player.ben.air.Value;
	}
	local success, errormessage = pcall(function()
		mydatastore:SetAsync(playeruserid, data) -- funtion that sets the async 
	end)
	if success then
		print("Datasuccesfuly saved")
	else
			print("There was an error")
			warn (errormessage)
	end
	
end)

2 comments

0

Which line is erroring?

0

Which ever line is listed first under if success then, in this case fire

1 answer

I solved it I just needed to do fire.Value = player.ben.fire.Value; and so on in line 46

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