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

Why do I get the nil error of the Vector of the second argument in the cframes?

Hello, good morning, what does that throw me that is nil the second argument in SetPrimaryPartCFrame because my global variable is nil, what am I doing wrong? I need help. I'm very stressed with this.

local DataStoreService = game:GetService("DataStoreService")
local positionStore0 = DataStoreService:GetDataStore("Position0")
local ground = game.Workspace.Ground

local function encode_cframe(cf)
   return string.format(string.rep("%f ",12), cf:components())
end

local function decode_cframe(cf)
   local tab = {}
	    for s in string.gmatch(cf, "%d+") do
	        table.insert(tab,tonumber(cf))
	    end
	    return CFrame.new(unpack(tab))
end



game("GetService", "Players").PlayerAdded:Connect(function(player)
    
    player.CharacterAdded:Connect(function(character)
	    cframeplayer = character:GetPrimaryPartCFrame() 
	    local get = positionStore0:GetAsync("Position0")
	    character:SetPrimaryPartCFrame(ground.CFrame * cframeplayer)
		print(get)
	    
	    character.Humanoid.Died:Connect(function()
			
			
		end)
	end)
end)


game("GetService", "Players").PlayerRemoving:Connect(function(player)
	player.CharacterRemoving:Connect(function(character)
		local set = positionStore0:SetAsync("Position0", encode_cframe(cframeplayer))
		print(set)
		
	end)
end)

5 comments

0

You should work on consistency a bit. On line 1 you're doing game:GetService yet on lines 19 and 35 you're doing game("GetService", "Players")

0

That's not the problem

0

My problem is that I do not know how to load the cframe of the position I keep or charge.

0

I never said it was. I just said you should be more consistent

0

There are many ways of doing things

1 answer

local DataStoreService = game:GetService("DataStoreService")
local positionStore0 = DataStoreService:GetDataStore("Position0")
local ground = game.Workspace.edificios.urbano.Ground.suelo
local players = game:GetService("Players")

local function encode_cframe(cf)
   return string.format(string.rep("%f ",12), cf:components())
end

local function decode_cframe(cf)
   local tab = {}
	    for s in string.gmatch(cf, "%d+") do
	        table.insert(tab,tonumber(cf))
	    end
	    return CFrame.new(unpack(tab))
end

players.PlayerRemoving:Connect(function(player)
	player.CharacterRemoving:Connect(function(character)
		cframeplayer = character:GetPrimaryPartCFrame()
		
		local set = positionStore0:SetAsync("Position0", encode_cframe(cframeplayer))
		print(set)
		
	end)
end)

players.PlayerAdded:Connect(function(player)
    
    player.CharacterAdded:Connect(function(character)
	   
	    local get = positionStore0:GetAsync("Position0")
	    character:SetPrimaryPartCFrame(ground.CFrame + cframeplayer)
		print(get)
	    
	    character.Humanoid.Died:Connect(function()
			
			
		end)
	end)
end)

It gives me the same error

10:34:42.155 - ServerScriptService.Script:33: bad argument #2 to '?' (Vector3 expected, got nil)

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