Datastore: Attempt to connect failed: Passed value is not a function

I’m trying to create a datastore for player’s leaderstats in my simulator game.

When I run the game I get an error code (Attempt to connect failed: Passed value is not a function) and there is a red line under the word “save” which is punched into the onShutdown local function to save the player’s data.


Here is where the function was created, which is right above the error.

I searched Youtube, developer hub, and asked around on Discord but I couldn’t figure it out.

7 Likes

Are you somehow redefining “save” somewhere else in your code?

Try using ctrl + f to search.

2 Likes

No, it’s only in those three spots I showed.

2 Likes

Move your mouse on the highlighted line. What does it say?

2 Likes

2 Likes

In your second screenshot, save() looks like is indented. Can you zoom out please?

2 Likes

2 Likes

Try this or check if you’re missing an end to see if it works

Players.PlayerRemoving:Connect(function(player)
	save(player)
end)
2 Likes

Your function is defined either inside another function, or inside a do end block

It is out of scope for the PlayerRemoving() event to use.
Please move it to the global space.

2 Likes

If you’re confused, here’s a tutorial on what this means:

(This is not for lua, but is still relevant!)

1 Like


There’s no longer a line under save, but now there is one on onShutdown

2 Likes

image

Why are your indentations so inconsistant?

Try and make them more consistant so you can see where you’re missing an “end” more easily.

1 Like

OHHH Thank you so much. I just had to rearrange my indentations, this helped a lot. I’m very new to scripting and I didn’t realize that mattered. Thanks!

1 Like

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