I need help scripting support

Hey, I want help with something in scripting, it’s not a full script or anything i just need help with one thing.

So there is the Player Character in the workspace and there is the player in the “Players” section of the game, and i want to know how i can access the “Players” part of the game by a player touching a brick, i can give more information if this is not enough. Thanks!

1 Like

There is a event called Touched and you can use it to detect when someone touches a part. To be able to access the person in the players section you will have to use a function from players called :GetPlayerFromCharacter()

But be aware that the Touched event gives the part that touched it, meaning that you will have to do :GetPlayerFromCharacter(parent of the thing that touched), because what touches is a part and not the character.

Basically:

Players:GetPlayerFromCharacter(bodyPart.Parent)

3 Likes

If you want to access a player from a playercharcater, do;

local character = game.Players.MyPlayerName -- Change path as desired
game.Players:GetPlayerFromCharacter(character)

GetPlayerFromCharacter is a very good tool for this.

Just so i can get better support, how can i detect if its a player thats touching the part?
Can i use WaitForChild(“Humanoid”)?

You dont really need that, the GetPlayerFromCharacter function does 2 things:

1- Checks if the model given is the character of the player

2- If so then it will return the player, else it will return nil

Example:

local randomModel = Instance.new("Model")
randomModel.Parent = workspace
print(game.Players:GetPlayerFromCharacter(randomModel)) -- nil

-- In case it was the character of the player..

print(game.Players:GetPlayerFromCharacter(playerCharacter).UserId) -- Prints the userID
1 Like

For future references put your problem in the title so people know what your problem is at first glance and then they can resort to help you if they are capable

1 Like

Sure thing, thanks for the advice