Here is what it says in the output: "12:35:22.258 - GetPlayerFromCharacter is not a valid member of Model"
The code is here:
1 | script.Parent.Touched:connect( function (otherPart) |
2 | if not otherPart.Parent:WaitForChild( "Humanoid" ) then end |
3 | local player = otherPart.Parent:GetPlayerFromCharacter() |
4 | player:Kick( "Sucks to be you!" ) |
5 | end ) |
The problem is that GetPlayerFromCharacter
is a member of game.Players
, not the model.
Instead, you must do this:
1 | script.Parent.Touched:connect( function (otherPart) |
2 | local player = game.Players:GetPlayerFromCharacter(otherPart.Parent) |
3 | if player then |
4 | player:Kick( "Sucks to be you!" ) |
5 | end |
6 | end ) |
Note that you should also check to see if the character is a player before trying to kick them. This also renders the first check redundant (it had a few problems anyway).
GetPlayerFromCharacter
GetPlayerFromCharacter
was supposed to be a function of Players, but nice try!
Here is the edited script:
1 | script.Parent.Touched:connect( function (otherPart) |
2 | if not otherPart.Parent:WaitForChild( "Humanoid" ) then end |
3 | local player = game.Players:GetPlayerFromCharacter(otherPart.Parent) -- Access Players to call the GetPlayerFromCharacter function!!! |
4 | player:Kick( "Sucks to be you!" ) |
5 | end ) |
Don't forget where to access and call different built-in functions the next time you script!
If you have any problems, please leave a comment below. Thank you and I hope this will help you!