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)
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)
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!
Bro I really appreciate it :)
This discussion is preserved as it was. New answers, comments, and votes are closed.
6 comments
Who is the mainplayer?
who is mainplayer
MainPlayer is the player that the script is parented to
So MainPlayer is a Player object? Or the player's character?
MainPlayer is the player in the Workspace sorry for the bad description
may i know why u need it to not detect the player touching it?