Unable to cast Instance to bool

I’m Trying To Create A Team Save System And I Can Save It But It Won’t Load The Team Saved And Just Keeps Giving Me This Error

image

Here Is The Script

Can Anyone Figure Out How To Fix This?

Can you show more of the code and the error line number?

yeah here, sry

and when i click the error it sends me to line 47

It looks like this error is happening in a different file.

1 Like

what do you mean that it looks like it is happening in a different file?

The error says DATA:47, can I see that code?

here is the full code

and here is the code that it says the error is from(it’s not line 47 in the full screenshot because i removed some notes from it)

I am confused. While looking at the screenshot, I also thought it was an error on line 47 …

I am finding it very difficult to pinpoint the problem in the code you’re showing. We can make this easier just by debugging right before this one your showing
plr.Team = Teams:FindFirstChild(teamStore:GetAsync(plr.UserId))

Can you print teamstore results also your double usage of :GetAsync I don’t think that’s very efficient

typing an example in a min

1 Like

When I Do that This Is What Teamstore gives


DataStore:GetAsync returns an instance that you have to then query for the actual result.
GlobalDataStore | Documentation - Roblox Creator Hub
DataStoreKeyInfo | Documentation - Roblox Creator Hub

1 Like

how do you think i should implement it into my code without ruining the random team function if the player is joining for the first time? I don’t want to mess it up when trying to do this on my own.

Something like this. You should definitely wrap this in a pcall and stop calling it more than once.
I can’t really do more since I don’t know how you’re saved data looks.

local result
local success, err = pcall(function()
	result = teamStore:GetAsync(plr.UserId)
end)
if not success then 
    warn(err) 
    return 
end

if result then
	plr.Team = result["<property name>"]
else
	RandomTeam(plr)
end

what am i supposed to put in the
[“< property name>”] part?
I’m A Little Unsure.

–edit–
nvm I think i figured it out

I cant tell you exactly what to put because I don’t know how you’re saving your data.

ok, now i just need to figure out why it won’t save