Getting the player

This is not specific enough. Changes in backpack and PlayerGui (NOT StarterGui, you should not be operating on items there) can mean anything.

If the function of the touch is unimportant (for example, making a Gui visible), then stop what you’re doing as your interpretation of how to do this presents unnecessary work for the server. Have the client register the touch instead. This way, they can handle both the touch and use the LocalPlayer variable.

Sample code (should be somewhere in StarterPlayerScripts ideally):

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local PartToTouch = somewhere -- obvious what needs to go here

PartToTouch.Touched:Connect(function (hit) -- is a BasePart, not a Player
    local player = Players:GetPlayerFromCharacter(hit) -- don't need
    if player and player == LocalPlayer then -- verify LocalPlayer did the touch
        print(player.Name) -- player is the same as LocalPlayer if it reaches this
    end
end)
1 Like

Probably is I’m using int values and not touched events there are no parts. Thanks anyways I’m probably going to use a Remote event.

tell us what you need it for and we can help

Hey! I’d like to tell you its not possible to achieve what you are trying to achieve, you can’t get the player from a value changing in a block.

1 Like

Alright. That’s what I was afraid
of thanks for letting me know.

1 Like

The best, and easiest way that I know of is to get the player by typing this:

local Player = game:GetService("Players").LocalPlayer

local characs = Player.Character -- This is the character

The code I mentioned above must be in a localscript or else it won’t work.

5 Likes