Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)



3 comments

0

You can repeat variable names so long as you know which scope they belong to

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

0

mis-judge*, lol

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)


8 comments

0

oh welp - that was simple - i'm dumb XD - Thanks for the answer though!

0

Not everything is fine. ree.

0

???

0

aw looks like my answer wasnt accepted even though i posted it first .-.

0

This one isn't correct. I'll upvote after you fix it.

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

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

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.