Profile service not working

So close to fixing this whole mess, all I have left it this error:

attempt to index nil with GoldenHookEquipped

this is the line of code:

if data.GoldenHookEquipped == false then

this is the data path:

local DataManager = require(game:GetService("ReplicatedStorage").DataManager)
local data = DataManager:Get(Player)

this is my data manager:

local Players = game:GetService("Players")
local ProfileService = require(script.Parent.ProfileService)

local ProfileStore = ProfileService.GetProfileStore(
	"Player",
	{
		Coins = 0;
		GoldenHookOwned = false;
		GoldenHookEquipped = false;
		TPoseOwned = false;
		TPoseEquipped = false;

	}
)

local Profiles = {}

local function onPlayerAdded(player)
	local profile = ProfileStore:LoadProfileAsync(
		"Player_" .. player.UserId,
		"ForceLoad"
	)

	if profile  then
		profile:ListenToRelease(function()
			Profiles[player] = nil
			player:Kick()
		end)

		if player:IsDescendantOf(Players) then
			Profiles[player] = profile
		else
			profile:Release()
		end
	else
		player:Kick()
	end
end
local function onPlayerRemoving(player)
	local profile = Profiles[player]
	if profile then
		profile:Release()
	end
end

Players.PlayerAdded:Connect(onPlayerAdded)
Players.PlayerRemoving:Connect(onPlayerRemoving)

local DataManager = {}

function DataManager:Get(player)
	local profile = Profiles[player]

	if profile then
		return profile
	end
end

return DataManager

data is nil. Try checking if data isn’t nil like:

if data then
end

I may be remembering wrong, but I believe the Reconcile function sorts this in ProfileService.

https://madstudioroblox.github.io/ProfileService/api/#profilereconcile

You’d use this before ListenToRelease in onPlayerAdded.

profile:Reconcile()

okay, get ready for a BIG script.

I did your thing and it only prints 1 and 2

--//Main Variables//--
local event = script.Parent.EPressed
local replicatedStorage = game:GetService("ReplicatedStorage")
local HookModel = replicatedStorage.Hook.Union
local GoldModel = replicatedStorage.HookGolden.Union

--//Script//--
event.OnServerEvent:Connect(function(Player,Action,MouseHit)
	
	print("1")
	
	--//Player Variables//--
	local NumberOfHooks = Player:WaitForChild("NumberOfHooks")
	local AmountOfHooks = NumberOfHooks:WaitForChild("Amount")
	local DataManager = require(game:GetService("ReplicatedStorage").DataManager)
	local data = DataManager:Get(Player)	
	--//Checks if hook is already out//--
if AmountOfHooks.Value == 0 then
		print("2")
		--//More variables//--
	 local char = Player.Character
	 local Hum = char:WaitForChild("Humanoid")
	 local HumRP = char:WaitForChild("HumanoidRootPart")
		
	 local TS = game:GetService("TweenService")
		
		--//If key pressed is E then continue//--
	 if Action == "E" then
			
			--//Diffrent Hooks//--
	local GoldProjectile = GoldModel:Clone()	
			
			
			--//Default hook Script//--
if data then
	print("3")			
				if data.GoldenHookEquipped.Value == true then --//Golden Hook script//--
				GoldProjectile.Parent = workspace
				GoldProjectile.CanCollide = false
				GoldProjectile.CFrame = HumRP.CFrame * CFrame.new(0,3,0)
				GoldProjectile.CFrame = CFrame.new(GoldProjectile.Position,MouseHit.p)

				local Tween = TS:Create(GoldProjectile,TweenInfo.new(3),{CFrame = GoldProjectile.CFrame * CFrame.new(0,0,-130)})
				Tween:Play()

				GoldProjectile.Touched:Connect(function(Hit)
					local db = false
					if Hit.Name == "Union" then
						if not db then
							db = true



							local HookPostition = GoldProjectile.Position
							local NewHook = GoldModel:Clone()
							NewHook.Parent = workspace
							NewHook.Position = HookPostition
							NewHook.Anchored = true
							NewHook.Rotation = GoldProjectile.Rotation
							NewHook.Name = "HookUsed"
							local Rope2 = Instance.new("RopeConstraint")
							Rope2.Attachment0 = NewHook.Attachment
							Rope2.Attachment1 = Player.Character:FindFirstChild("Torso").BodyFrontAttachment
							Rope2.Thickness = .2
							Rope2.Visible = true

							Rope2.Length = (NewHook.Position - Player.Character.HumanoidRootPart.Position).magnitude - 1





							Rope2.Parent = NewHook
							AmountOfHooks.Value = AmountOfHooks.Value + 1
						end
					end
					GoldProjectile:Destroy()
					db = false
				end)


				game.Debris:AddTag(GoldProjectile,2.5)

				delay(.6,function()
					local Tween = TS:Create(GoldProjectile,TweenInfo.new(0.3),{Transparency = 1})
					Tween:Play()
					if AmountOfHooks.Value <= 0 then
			 end
		 end)
	  end					
   end					
			
else
		print("4")	
			local HookProjectile = HookModel:Clone()

			
			HookProjectile.Parent = workspace
			HookProjectile.CanCollide = false
			HookProjectile.CFrame = HumRP.CFrame * CFrame.new(0,3,0)
			HookProjectile.CFrame = CFrame.new(HookProjectile.Position,MouseHit.p)



			local Tween = TS:Create(HookProjectile,TweenInfo.new(3),{CFrame = HookProjectile.CFrame * CFrame.new(0,0,-130)})
			Tween:Play()

			HookProjectile.Touched:Connect(function(Hit)
				local db = false
				if Hit.Name == "Union" then
					if not db then
						db = true



						local HookPostition = HookProjectile.Position
						local NewHook = HookModel:Clone()
						NewHook.Parent = workspace
						NewHook.Position = HookPostition
						NewHook.Anchored = true
						NewHook.Rotation = HookProjectile.Rotation
						NewHook.Name = "HookUsed"
						local Rope2 = Instance.new("RopeConstraint")
						Rope2.Attachment0 = NewHook.Attachment
						Rope2.Attachment1 = Player.Character:FindFirstChild("Torso").BodyFrontAttachment
						Rope2.Thickness = .2
						Rope2.Visible = true

						Rope2.Length = (NewHook.Position - Player.Character.HumanoidRootPart.Position ).magnitude - 1

						local bodyGyro = Instance.new("BodyGyro")
						bodyGyro.Parent = NewHook
						Rope2.Parent = NewHook

						AmountOfHooks.Value = AmountOfHooks.Value + 1


					end
				end
				HookProjectile:Destroy()
				db = false
			end)


			game.Debris:AddTag(HookProjectile,2.5)

			delay(2.2,function()
				local Tween = TS:Create(HookProjectile,TweenInfo.new(0.3),{Transparency = 1})
				Tween:Play()
				if AmountOfHooks.Value <= 0 then
				end
			end)		
end	
			
	elseif AmountOfHooks.Value >= 1 then    
		end
	
end)

Yeah, it doesn’t print 3 because data is nil.

but there is an else statement for that.

I think you messed up then. The else statement is in the

if Action == "E" then

if statement.

oh, how do I fix it then? It still looks fine to me.

Which if statement do you want the else statement in?
Look for it and place it inside of that if statement.
For now its

if Action == "E" then
  -- something
else
  print("4")
end

I don’t know if you want it inside of that statement

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