Hello, I'm trying to make a tycoon place, personally for mine only for script practice and testing. What I am currently wandering is what type of object should I put my script in. Should I put it in the normal one 'Script' or in the 'LocalScript'? I don't know what's the difference between them to be honest. Here is my script though! If someone could make it simpler, it would be cool. I haven't tested it online though, only 'Play Solo'.
function onPlayerJoin(newPlayer) local stats = Instance.new("IntValue") stats.Name = "Leaderstats" stats.Parent = newPlayer local cash = Instance.new("IntValue") cash.Parent = stats cash.Name = "Cash" cash.Value = 100 local stats2 = Instance.new("IntValue") stats2.Name = "Tycoon" stats2.Parent = newPlayer end game.Players.ChildAdded:connect(onPlayerJoin)
The difference between normal scripts (called server scripts) and local scripts is that server scripts run on the server and local scripts run on the client.
Basically, server scripts run on Roblox, while local scripts run on the player's computer. Because of this, local scripts will only run in PlayerGui, Backpack, or the player's character.
You should always use local scripts if you intend to make it a descendant of a player, or inside a character. Server scripts may not work as expected sometimes inside a player.
For your code, it should be a server script inside ServerScriptService or workspace because there is no need to put it inside a player, since you use the ChildAdded event.
Two problems with it though. Instead of ChildAdded, you should really use the PlayerAdded event. Second, 'leaderstats' should always be spelled with a lower case L, assuming you want it to appear on the leaderboard.