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

Why does studio think that the script should end on line 3? (about Players and Characters , I think)

Asked by 5 years ago

Good Evening (or morning :P), i hope you all have had a great day so far, now it's time to make it worse as you have to answer my amateur scripting question!

So in the script below it is apparently supposed to ServerScriptService.Script:7: ')' expected (to close '(' at line 3) near '<eof>' - I have to clue what that means, can someone please walk me through this -

yours goku :D

local player = game:GetService("Players")


player.PlayerAdded:Connect(function(person)
    person:CharacterAdded(function(person)
        print(person.Parent)
    end)
end)


2 answers

Log in to vote
0
Answered by
xPolarium 1388 Moderation Voter
5 years ago
Edited 5 years ago

Not correctly connecting it to the function.

--proper variable naming. 
local players = game:GetService("Players")

players.PlayerAdded:Connect(function(person)
    person.CharacterAdded:Connect(function(character)
        print(person.Parent)
    end)
end)



0
You can repeat variable names so long as you know which scope they belong to aazkao 787 — 5y
0
Again mate dont mid-judge my comment, not defending it or saying that naming the variables the same is better, just saying that you can do it aazkao 787 — 5y
0
mis-judge*, lol aazkao 787 — 5y
Ad
Log in to vote
0
Answered by
aazkao 787 Moderation Voter
5 years ago
Edited 5 years ago

CharacterAdded is an event not a function you need to use . not : , and connect the function to the event, also not sure about the error you are getting, everything is fine other than your CharacterAdded event

local player = game:GetService("Players")


player.PlayerAdded:Connect(function(person)
    person.CharacterAdded:Connect(function(person)
        print(person.Parent)
    end)
end)


0
oh welp - that was simple - i'm dumb XD - Thanks for the answer though! ScriptingNubs 55 — 5y
0
Not everything is fine. ree. xPolarium 1388 — 5y
0
??? aazkao 787 — 5y
0
aw looks like my answer wasnt accepted even though i posted it first .-. aazkao 787 — 5y
View all comments (4 more)
0
This one isn't correct. I'll upvote after you fix it. xPolarium 1388 — 5y
0
What??? you talking about the repeated person variable? they are different objects mate, go test it in studio yourself by printing out the parent of each person variable, they are contained within their own scope aazkao 787 — 5y
0
The variable in the CharacterAdded scope will be a child of workspace while the variable in the PlayerAdded scope will be a child of players, its all working as intended in studio aazkao 787 — 5y
0
It won't work when you need to access something from the player AND character. Terrible scripting advice that I see no reason why you're defending. xPolarium 1388 — 5y

Answer this question