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

How do you make a hit function Ignore certain parts?

My script detects Players but I 'm trying to get the (hit) to not detect Mainplayer

part.Touched:Connect(Function(hit)
	if hit ~= Mainplayer then
	----- script
	
	
end)

6 comments

0

Who is the mainplayer?

0

who is mainplayer

0

MainPlayer is the player that the script is parented to

0

So MainPlayer is a Player object? Or the player's character?

0

MainPlayer is the player in the Workspace sorry for the bad description

0

may i know why u need it to not detect the player touching it?

1 answer

✓ Accepted answer

There is a function called GetPlayerFromCharacter(Char) of players that gets the player object from the given character model.

local mainPlayer = game.Players:GetPlayerFromCharacter(script.Parent)

part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then -- check if player is a character
		local character = hit.Parent
		local player = game.Players:GetPlayerFromCharacter(character)
		if player ~= mainPlayer then
			-- do this if the player is someone else other than the main player
		end
	end
end)

Hope this helps, if you have any questions please let me know!

1 comment

0

Bro I really appreciate it :)

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