Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help at my script please?

Asked by 10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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)

1 answer

Log in to vote
2
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

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.

0
What's the problem between ChildAdded and PlayerAdded event? Pacified 15 — 10y
0
PlayerAdded events do not work well in local scripts, so in them you should use ChildAdded. However, if you're using a server script you should use PlayerAdded because it is built specifically for PLAYERS joining the game, while ChildAdded just fires every time an instance is added to the object it is used on. Perci1 4988 — 10y
0
Alright, thanks. Very helpful Pacified 15 — 10y
Ad

Answer this question