Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you make a hit function Ignore certain parts?

Asked by 4 years ago
Edited 4 years ago

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)
0
Who is the mainplayer? Nanomatics 1160 — 4y
0
who is mainplayer Geobloxia 251 — 4y
0
MainPlayer is the player that the script is parented to ffancyaxax12 181 — 4y
0
So MainPlayer is a Player object? Or the player's character? Nanomatics 1160 — 4y
View all comments (2 more)
0
MainPlayer is the player in the Workspace sorry for the bad description ffancyaxax12 181 — 4y
0
may i know why u need it to not detect the player touching it? guest_20I8 266 — 4y

1 answer

Log in to vote
1
Answered by
Nanomatics 1160 Moderation Voter
4 years ago
Edited 4 years ago

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!

0
Bro I really appreciate it :) ffancyaxax12 181 — 4y
Ad

Answer this question