Datastore working in Roblox Studio but fails in game

Well, you are creating a function every time that is running. I would recommend reading this topic on pcalls.

1 Like