How to get LocalPlayer with touchevent?

Hello Everyone! Dont flag this there isnt much to say about

Edit: I want paste my Gui in the LocalPlayer btw in the PlayerGui and seems like thats just possible with PlayerGUi

sword.Touched:Connect(function(hitted)
– if hitted ~= player.Character and not hitted:IsDescendantOf(player.character) then
local HumanoidRootPart = hitted.Parent:FindFirstChild(“HumanoidRootPart”)
local HumanoidNPC = hitted.Parent:FindFirstChild(“Humanoid”)
local plr = game.Players:GetPlayerFromCharacter(hitted.Parent)
Combat1:FireClient(plr)

**But how can I get the Local player ? I need to find the Localplayer. **
Because when I dont find this happen after I fireClient:

AND YES I TESTED ALSO WITH LOCALPLAYER STILL ERROR

if not plr:FindFirstChild("MenuGui") then
		local AttackCollection2 = plr.PlayerGui.AttackCollection
		AttackCollection2.Enabled = true
		AttackCollection2.Parent = plr.LocalPlayer.PlayerGui
		AttackCollection2.Enabled = true
	end

and thats with LocalPlayer:

1 Like

You would do something like this:

BasePart.Touched:Connect(function(object)
   local player = game:GetService("Players"):GetPlayerFromCharacter(object.Parent)

   if player then
       -- it's from a player, do stuff here
   end
end)
1 Like

I actually want find the localplayer could you finish ur example?

If you’re using a local script, just do this:

local player = game:GetService("Players").LocalPlayer
1 Like

actually no it doesnt work. Maybe somethingelse

1 Like

why do you write game:GetService(“Players”) we want find the touched

1 Like

Elaborate on what you want to accomplish. If you want to find the player that touched the part, then do what @HugeCoolboy2007 suggested. LocalPlayer only exists in LocalScripts and Modules required from a LocalScript

1 Like

actually but if I want find the touched I do not write GetService??

We know that LocalPlayer is just in LocalPlayer

thats why I am trying to figure out how I can solve this missing nil

I don’t understand what you’re trying to do, if you want to get the LocalPlayer from a local script then you just do

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

and then you can do whatever with the player variable

if not player:FindFirstChild("MenuGui") then
    --
end

I am sorry but you just wrote what I did. Again, it will be a touched event, so we need from the touched event the Localplayer for copy my Gui in it. We dont want the player that is not touched. We just want the player that is touched, as you can see in my script.

What I use is:

script.Parent.Touched:Connect(function(hitted)
if hitted:FindFirstChild("Humanoid") then
local player = game.Players:FindFirstChild(hitted.Name)
--~~code here~~
end)

but I want make a FireClient so for getting the LocalPlayer

1 Like

I don’t understand what you’re trying to accomplish here.

1 Like

I edit a bit my post now for understanding it better

in a localscript

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

Combat1.OnClientEvent:Connect(function()
	if not player:FindFirstChild("MenuGui") then
		local AttackCollection2 = player.PlayerGui.AttackCollection
		AttackCollection2.Enabled = true
	end
end)

Cant you see the Gui I want paste in the player that was touched???

so where is the touched player?

If you cant understand then you didnt understand the problem. again I want put the gui in the player that was touched. Touched, do you know? sword.Touched. If you still didnt understand I am sry