"Attempt to index number with 'Value' " errormessage in Obby

  1. What do you want to achieve? I wanna set the leaderstats (display) stage to the actual stage the player is currently on.

  2. What is the issue? The issue is the errorCode in the title. For the line, it gives me the .changed Event.

  3. What solutions have you tried so far? I tried to add or remove the .Value from a few lines now but nothing changed exept for the errorCode saying ‘Value’ instead of ‘Changed’ now. It said ‘Changed’ before.
    image

To make the problem more clear, I put my script down below. The CurrentStage is stored inside of a Folder inside of the Serverstorage while the the Stage (Leaderstats) is stored in the players leaderstags. The CurrentStage is controlled by annother script but I dont think it is important to show. The only thing that might be important is the transfer to a Number instead of a string value here:
image

Thank you for reading and your time!

local DataStoreService = game:GetService("DataStoreService")
local DataStore1 = DataStoreService:GetDataStore("dwaofwaaf")
local ServerStorage = game:GetService("ServerStorage")
local spawns = workspace.Spawns

game.Players.PlayerAdded:Connect(function(player)
	local DataFolder = Instance.new("Folder")
	DataFolder.Name = "DataFolder"
	DataFolder.Parent = ServerStorage
	
	local PlayerDataFolder = Instance.new("Folder")
	PlayerDataFolder.Name = player.Name.."_"..tostring(player.UserId)
	PlayerDataFolder.Parent = DataFolder
	
	local currentStage = Instance.new("IntValue")
	currentStage.Name = "CurrentStage"
	currentStage.Parent = PlayerDataFolder

	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local stage = Instance.new("IntValue")
	stage.Name = "Stage"
	stage.Parent = leaderstats
	stage.Value = currentStage.Value
	
	local playerUserId = "Player_"..player.UserId
	
	local data
	local success, errormessage = pcall(function()
		data = DataStore1:GetAsync(playerUserId)
	end)
	
	if success then
		if data then
			stage = data.stage
			currentStage = data.currentStage
			player.RespawnLocation = spawns[tostring(currentStage)]
			player:LoadCharacter()
		else
			stage.Value = 1
			currentStage.Value = 1
			player.RespawnLocation = spawns["1"]
			player:LoadCharacter()
		end
	else
		warn(errormessage)
	end
	
	currentStage.Changed:Connect(function()
		stage.Value = currentStage
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	local playerUserId = "Player_"..player.UserId
	
	local data = {
		stage = player.leaderstats.Stage.Value;
		currentStage = ServerStorage.DataFolder:WaitForChild(player.Name.."_"..tostring(player.UserId)).CurrentStage.Value
	}
	
	local success, errormessage = pcall(function()
		DataStore1:SetAsync(playerUserId, data)
	end)
	
	if success then
		print("Data for Player "..player.Name.." with Id "..tostring(player.UserId).." was saved!")
	else
		warn(errormessage)
	end
end)

The issue arrises from an issue in the if success then if data then ... part

You have it as

stage = data.stage

However, I believe you intended to do

stage.Value = data.stage
2 Likes

Well, that happens if you don’t look carefully… thank you very much!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.