Basically, RoomOneTable[1]
== Workspace.EEnergy8
I'm trying to get the Player from Character
Error: attempt to index nil with 'Name
1 | local playerRoomOneOne = game.Players:GetPlayerFromCharacter(RoomOneTable [ 1 ] ) |
2 | print ( "Player one from the table, 1 is: " ..playerRoomOneOne.Name) |
You are currently trying to get the player from the object instead of a character which is why it is not working. The thing you need to do is check if something touches the part. If it has a humanoid then the parent of it is a character. You can then GetPlayerFromCharacter and run the rest of your script.
I have attached a sample script below.
01 | --VARIABLES: |
02 |
03 | --In this case you would want to reference the table instead ie game.Workspace.EEnergy8 |
04 | local Part = game.Workspace.Part |
05 | local Players = game:GetService( "Players" ) |
06 |
07 | --hit is the thing which touches the part (or in your case table) |
08 | Part.Touched:Connect( function (hit) |
09 |
10 | --In order to get the player from character you first need to find a character. |
11 | --All characters have humanoids so first check if whats touching the table has a humanoid. |
12 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
13 |
14 | --We know hits parent is the character because it has a first child of humanoid. |
15 | --Now we can use Players:GetPlayerFromCharater |