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

how do you check if the character touching a brick is the local player?

i made a camera system for a game using .Touched to change perspective but if another player touches the brick it still changes the camera perspective. does anyone know how to check if the player touching the brick is the local player?

--local script
workspace["int 2"].Touched:Connect(function()
	workspace.CurrentCamera.CFrame = workspace["cam int 2"].CFrame
end)

2 answers

That's easy

workspace["int 2"].Touched:Connect(function(hit)
	if hit.Parent;FindFirstChild("Humanoid") then
		
		local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)

		-- Code here
		
	end
end)

4 comments

0

No that would just check that it was a player, not the localplayer.

0

no I check if it's a character and then the character that touches it it get's the player

0

The OP is trying to see if the player who touches it is the LocalPlayer in the script, not just a player in general.

0

...

You would need to check if they're the same player.

local players = game:GetService("Players")

workspace["int 2"].Touched:Connect(function(hit)
  if hit.Parent:FindFirstChild("Humanoid") then

    local player = players:GetPlayerFromCharacter(hit.Parent)
    if player == game.Players.LocalPlayer then
      workspace.CurrentCamera.CFrame = workspace["cam int 2"].CFrame
    end
  end
end)

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