An error a understand, but cannot fix

I am getting the error “Attempt to index nil with blah blah blah” (It doesnt actually say blah blah blah but you get the point) And I know that means i’m trying to identify something that does not or is yet to exist, the problem is to make them exist I need them to exist. Its really weird so just look at this script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage.GoldBought
local RemoteFunction = ReplicatedStorage.ShopRemoteFunction

Event.OnServerEvent:Connect(function(Player,HookType)
	local Folder = Player:WaitForChild("leaderstats")
	local IntValue = Folder:WaitForChild("Coins")
	
	local DataManager = require(game:GetService("ReplicatedStorage").DataManager)
	local data = DataManager:Get(Player)
	
	
	
	local TPoseEquipped = data.TPoseEquipped
	local TPoseOwned = data.TPoseOwned
	local GoldenHookEquipped = data.GoldenHookEquipped
	local GoldenHookOwned = data.GoldenHookOwned
	
	RemoteFunction:InvokeClient(TPoseEquipped,TPoseOwned,GoldenHookEquipped,GoldenHookOwned)
	
	
 if HookType == "GoldenHook" then
	if GoldenHookOwned.Value == false then
		if IntValue.Value >= 1 then
			IntValue.Value = IntValue.Value - 1
				
			GoldenHookOwned.Value = true
           end
		end
	elseif HookType == "TPose" then
		if TPoseOwned.Value == false then
			if IntValue.Value >= 1 then
				IntValue.Value = IntValue.Value - 1

				TPoseOwned.Value = true
			end
		end
	
	end
end)

Notice how I am trying to give a value to these things (TPose, GoldenHook, ect) but since they do not exist I can not reference them, I need you guys to help me. How do I reference/change their value. Also if it helps this is a profile service issue, and this is my data manager (My first EVER data manager so dont judge)

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
4 Likes

For the love of everything Roblox please quit posting new threads about the same script!

The information on each thread is important and can help others understand your issue. If you keep posting new threads you’ll have to answer all those questions again.

Please be a little more patient. Usually you need to wait a few days for someone who can help you to read your post. Everyone here volunteers their time and efforts so they aren’t on 24/7.

Profile service not working
Profile service no worky
Can someone please help me
Script not running
Error code: "Unable to cast value to object"

4 Likes

Okay, sorry about that. Which one should I keep, and I’ll take the others down.

EDIT:
I am sorry about all the posts, some of them are very similar but I geuss I thought that they were just barley different enough to have different posts. Also for me its seems the older the post the more my problem is kinda ignored, for example a have 1 or 2 posts that are months old and still havent been answered (But I did trouble shoot them eventually) Again very sorry.

2 Likes

No worries.
It’s just easier for someone troubleshooting to understand everything that’s been discussed or suggested already.

1 Like

Can anyone help me? I still havnt fixed this.

1 Like

Is leaderstats without the capital letter the correct spelling? All your other variables have a capital letter.

You have a WaitForChild for coins or leaderstats, but not for data. What if you use one there?

1 Like

The “blah blah blah” may be the most important part of that error message. Please state the full error message and point out exactly which line of which script is causing the error so we can best help.

If you just need default values you could edit your datamanager to return one; though I do not know how this is supposed to act with the profile service script mentioned.

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

	if profile then
		return profile
	else
		-- give default
		return {
			Coins = 0,
			GoldenHookOwned = false,
			GoldenHookEquipped = false,
			TPoseOwned = false,
			TPoseEquipped = false,
		}
	end
end
1 Like

It worked but now there is an error with my remote function:

“Unable to cast value to object”

to this line:

RemoteFunction:InvokeClient(TPoseEquipped,TPoseOwned,GoldenHookEquipped,GoldenHookOwned)

1 Like

If you print those values just before you use them in the script you can see what is being assigning to the variables and troubleshoot from there.

1 Like
  1. I am proud of you for programming.

  2. Optimize your program
    Why are you getting “ReplicatedStorage” after it was already defined? Check your top script, line about DataManager

  3. Try adding :WaitForChild()

-- Try:
local RemoteFunction = ReplicatedStorage:WaitForChild("ShopRemoteFunction")
 
-- Instead of:
local RemoteFunction = ReplicatedStorage.ShopRemoteFunction
  1. What client are you invoking?
RemoteFunction:InvokeClient(TPoseEquipped,TPoseOwned,GoldenHookEquipped,GoldenHookOwned)

You never specified the client to invoke
Read more @
RemoteFunction | Documentation - Roblox Creator Hub

Now a new error: attempt to index nil with ‘Changed’

But the only thing that has changed in it is the local script connected to it

local script:

RemoteFunction.OnClientInvoke = function(player,TPoseEquipped,TPoseOwned,GoldenHookEquipped,GoldenHookOwned)


GoldenHookOwned.Changed:Connect(function()
	if GoldenHookOwned == true then
		ShopFrame.SframeClip.SFrame.GHDecor.GHPrice.Text = "Owned"
	end
end)


TPoseOwned.Changed:Connect(function()
	if TPoseOwned == true then
		ShopFrame.AframeClip.AFrame.TPDecor.TPPrice.Text = "Owned"
	end
end)
	
end

btw this is only some of the script but I believe this is all you need to help me with this rabbit hole of errors.

.Changed does not exist.

Table index/key doesn’t have the same events/methods as an instance.

So is there any way to detect if my table has changed? It does not have to be a specific thing in the table btw, just the table itself would work fine as well.

Yes, there is a way; Metatables.

Metatables | Documentation - Roblox Creator Hub

You need a proxy (blank table) and __newindex() method/function

So there is no other way to access values in a normal table? I just tried to learn about what you told me to do and… it’s kinda confusing.

You can access the table by making it an assignment and treating it like a path. To detect change, you will need to use Metatables.

In that case, time to get on the learning grind.

I dont know whats going on but I think I really screwed up when I made that profile service thing I while back. I finally fixed my original issue, but then I printed my data and no matter what I do it is always the default data. It is not updating at all. Nothing.

Also I fixed the first issue by just deleting the .changed thing because I did not need it at all.

I think I know the problem, maybe. But help is always appreciated.

Edit:

I think the problem is that I cannot make a proper path to the data table, aka I think data.example will not work.

I am SOOOOOO close, an I am learning so many cool things, and I am 78.29% confident I can handle my problems from now on… except one. How do I access server script service from a client side script?

EDIT:

Might be able to fix EVERYTHING (amazing ik) but I wont say this is issue is solved until im done trouble shooting everything.