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 5 years ago
Edited 5 years ago

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

1part.Touched:Connect(Function(hit)
2    if hit ~= Mainplayer then
3    ----- script
4 
5 
6end)
0
Who is the mainplayer? Nanomatics 1160 — 5y
0
who is mainplayer Geobloxia 251 — 5y
0
MainPlayer is the player that the script is parented to ffancyaxax12 181 — 5y
0
So MainPlayer is a Player object? Or the player's character? Nanomatics 1160 — 5y
View all comments (2 more)
0
MainPlayer is the player in the Workspace sorry for the bad description ffancyaxax12 181 — 5y
0
may i know why u need it to not detect the player touching it? guest_20I8 266 — 5y

1 answer

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

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

01local mainPlayer = game.Players:GetPlayerFromCharacter(script.Parent)
02 
03part.Touched:Connect(function(hit)
04    if hit.Parent:FindFirstChild("Humanoid") then -- check if player is a character
05        local character = hit.Parent
06        local player = game.Players:GetPlayerFromCharacter(character)
07        if player ~= mainPlayer then
08            -- do this if the player is someone else other than the main player
09        end
10    end
11end)

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

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

Answer this question