ISSUE
Currently if the bullet is shot, it can hit the player I am aiming at and it can also hit myself. I don’t want it to run the script if it hits myself. I only want the script to work if it hits the other players. I’m not sure what to write in the script to avoid the bullet script impacting me the shooter.
I am using hit such as below
script.Parent.Touched:Connect(function(hit)
local player = hit.Parent
local torso = player.HumanoidRootPart
if torso then
if player then
end
end
end)
I thought about WhiteList and BlackList b/c I just learned about that in my tutor sessions… but it was a bit different project I accomplished. I wasn’t sure if I could also use it to shoot a player without affecting me. I still wouldn’t know what to put in the script to tell it I the shooter should not be affected.
What differentiates me from the other players so that the script knows not to affect me ? I don’t know the answer to this.
You should use Region3 or Raycast for projectiles, another thing I recommend is doing :FindFirstChild("HumanoidRootPart") instead of .HumanoidRootPart.
script.Parent.Touched:Connect(function(hit)
local player = hit.Parent
numberofteleports = 8
if player then
local HRP = player:FindFirstChild("HumanoidRootPart")
--local torso = player.HumanoidRootPart
if HRP then
for i = 1, numberofteleports do
n = math.random(1,8)
if n == 1 then
--torso.Position = Vector3.new(1147.297, -31.026, 155.285)
HRP.CFrame = CFrame.new(-84, 150, -224)
elseif n == 2 then
HRP.CFrame = CFrame.new(98, 150, -224)
elseif n == 3 then
HRP.CFrame = CFrame.new(-84, 150, 224)
elseif n == 4 then
HRP.CFrame = CFrame.new(98, 150, 224)
elseif n == 5 then
HRP.CFrame = CFrame.new(-84, 100, -224)
elseif n == 6 then
HRP.CFrame = CFrame.new(98, 100, -224)
elseif n == 7 then
HRP.CFrame = CFrame.new(-84, 100, 224)
elseif n == 8 then
HRP.CFrame = CFrame.new(98,100,224)
end
end
end
end
end)
In another game I was able to make the bullet only impact the monster and not other players by doing this
if hit.Parent:FindFirstChild(“monster”) then
But in order to enable this, In Explorer under the monster I had to change Character object which was named monster, I had to change the Humanoid to the name of monster.
I can’t do that with every shooter who picks up the gun and decides to shoot it in my game can I ?
All-righty I tried your suggestion and all though it still happens occasionally it seems to of helped prevent myself from being hit most of the time. In the attached video I only get hit one time as opposed to the prior video I was getting hit a-lot.