Code From A Tutorial Not Working

To improve my scripting skills, I decided to follow along on a tutorial on how to make a simulator. It was going well, and then it wasn’t. Literally halfway through the FIRST PART of the tutorial, and I was already going through errors.

The code was supposed to duplicate the leaderstats folder and parent it to the player whenever they join. It literally sounds top-tier simple, but whoop de do, I managed to mess it up.

I can’t find out what I did wrong, either. I wrote all the code almost exactly the same, as you can see here.

ModuleScript

My Code:


(Even though there’s an extra PlayerRemoved Event, the same error message appears when I )

The Tutorial:

MainServer (Where the error happens)

My Code:

The Tutorial:

As you can see, besides a few Capitalization changes (and the extra PlayerRemoved function I just took away), everything is basically the same. However, it works just fine for him and not for me, and the video isn’t that old (Made in August 6th of 2021)

What’s going on? Can someone help me?

Youtube Link to the Tutorial

Text Version of My Code So Y'all Don't Have to Type It Yourselves

ModuleScript:

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")

local Player_Data = ServerStorage.Player_Data

local PlayerData = {}

function PlayerData.playerAdded(player)
	for _, value in pairs(Player_Data:GetChildren()) do
		local cloned = value:Clone()
		cloned.Parent = player
	end	
end

return PlayerData

MainServer

local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local Server =  ServerScriptService.Server
local ServerModules = Server.Modules

local PlayerData = require(ServerModules.Player_Data)

Players.PlayerAdded:Connect(function(PlayerData.PlayerAdded)
	
	for _, player in next, Players:GetPlayers() do	
		coroutine.wrap(PlayerData.playerAdded)(player)
	end

Any errors? The code seems unnecessarily complex(for what you’re doing), but I don’t see anything directly that may be causing an issue.

yeah do you see a difference?


it’s painfully obvious.

also,

Better not be from a YouTube tutorial. Those videos get outdated quickly, you’ll end up learning bad scripting habits.

1 Like

Sorry, forgot to add the error. The error it shows for me is that on line 8 for MainServer, the Players.PlayerAdded:Connect(function(PlayerData.PlayerAdded) shouldn’t have a .PlayerAdded after PlayerData, but if I remove it, then it won’t work

As @Prototrode said above, remove function. Function is only used when your creating code inside of said function you want to run when X happens, not when your triggering event to happen when X occurs.

It’s because I’m painfully stupid. :frowning:

Well, I can’t find much other tutorials on how to make a basic simulator for free, (and I may be stupid but not stupid enough to actually ask how to make a scripting game in this section) so Youtube is kind of my best bet right now. Since you suggested it, I’ll try and find other resources, but It’s pretty hard for me.

And I just got rid of the function, and now it’s telling me “Attempt to connect failed: Passed value is not a function”

If I got anything else wrong, let me know because I legitimately suck.

if you want, you can read my full stance on youtube tutorials here:

There are plenty of tutorials in #resources:community-tutorials. Some of them might be good, and some of them might be bad. Another good place to learn from would be from #resources:community-resources, particularly popular resources/modules with a good reputation. Just crack open and disassemble some of the resources to see how they work and stuff like that

You forgot to capitalize. PlayerData.PlayerAdded is not the same as PlayerData.playerAdded, the latter being the one that’s defined in the module

also pro-tip: READ THE ERRORS! Most of the time that’s enough to tell you exactly what went wrong and what needs to be checked and fixed. The error message literally tells you that whatever you tried to use to connect isn’t a function. A simple check will reveal that PlayerData.PlayerAdded is in fact nil as it was never defined in the module.

Alright, thanks for the help! I’ll go and take a look at the resources you sent me. (I’m also abandoning the YT tutorial because its probably outdated already)

Also, because you seem a bit angry, I just want to apologize. While I have a pretty basic knowledge of scripting, I still have a lot to learn, so I mess up a lot of things, such as reading errors and such. I also did use YouTube as my previous go-to learning source, so I may have picked up some bad habits.
I end up posting here a lot because I usually can’t find a solution to the specific thing I’m trying to do, (or there is a solution and I was too stupid to look for it first) and usually the answer is right in front of me.
Once again, I’d just like to apologize if you think I wasted your time here. I’m still in the process of learning this kind of stuff, and I’m messing up a lot.

Not at all. Everyone started out as a newbie and we all needed help starting out. It’s just a piece of general advice to stay away from youtube tutorials because of their fundamental flaw of aging and eventual obscurity, along with some basic tips that everyone should know. It is going to take time to learn, and I wanted to wish the best of you.

1 Like

Yeah, i see a Difference in ur script is PlayerAdded small: PlayerData.playerAdded is in ur script and the Original Script has PlayerData.PlayerAdded, the P is small in ours

mining simulator is open sourced i think