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.
4 Likes
Are you somehow redefining “save” somewhere else in your code?
Try using ctrl + f to search.
1 Like
No, it’s only in those three spots I showed.
1 Like
Move your mouse on the highlighted line. What does it say?
1 Like
In your second screenshot, save() looks like is indented. Can you zoom out please?
1 Like
Try this or check if you’re missing an end to see if it works
Players.PlayerRemoving:Connect(function(player)
save(player)
end)
1 Like
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.
1 Like
SkrubDaNub
(ComradeSkrub)
June 27, 2023, 9:00pm
10
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
SkrubDaNub
(ComradeSkrub)
June 27, 2023, 9:06pm
12
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
system
(system)
Closed
July 11, 2023, 9:17pm
14
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.