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

how to get gun to not kill team, but still hurt barrier health?

Asked by
Tecara 0
9 years ago

So this is probably way wrong because I was getting desperate. Pretty much I want the gun to be able to hit other players, but not people of the same team. At the same time though, I need it to still damage a humanoid object that does not have a team like a player does, but a TeamColor value. (Again not being able to hit your teams) What am I doing wrong? Problem starts at: --do damage to any humanoids hit. Any help is appreciated.

local tool = script.Parent
local user
local d = false
damage = 8
--when the tool is equipped
tool.Equipped:connect(function(mouse)
--store the character of the person using the tool
user = tool.Parent

--when the left mouse button is clicked
mouse.Button1Down:connect(function()
if d == false then
d = true

--make and do a hit test along the ray
local ray = Ray.new(tool.Tip.CFrame.p, (mouse.Hit.p - tool.Tip.CFrame.p).unit*300)
local hit, position = game.Workspace:FindPartOnRay(ray, user)

--do damage to any humanoids hit
local p2 = game.Players:GetPlayerFromCharacter(hit.Parent)
local player = Game.Players.LocalPlayer
local humanoid = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid")
if humanoid and humanoid.Health > 0 and p2.TeamColor ~= player.TeamColor or humanoid.Health >0 and hit.Parent.Team.Value ~= player.TeamColor then
humanoid.Health = humanoid.Health - damage
player.PlayerGui.Storage.Value = player.PlayerGui.Storage.Value + damage/2

--draw the ray
local distance = (position - tool.Tip.CFrame.p).magnitude
local rayPart = Instance.new("Part", user)
rayPart.Name = "RayPart"
rayPart.BrickColor = BrickColor.new("Bright green")
rayPart.Transparency = 0.5
rayPart.Anchored = true
rayPart.CanCollide = false
rayPart.TopSurface = Enum.SurfaceType.Smooth
rayPart.BottomSurface = Enum.SurfaceType.Smooth
rayPart.formFactor = Enum.FormFactor.Custom
rayPart.Size = Vector3.new(0.2, 0.2, distance)
rayPart.CFrame = CFrame.new(position, tool.Tip.CFrame.p) * CFrame.new(0, 0, -distance/2)

--add it to debris so it disappears after 0.1 seconds
game.Debris:AddItem(rayPart, 0.1)
wait(1)
d = false
end
end
end)
end)
0
Try using parentheses to clarify what comparisons to do first. GoldenPhysics 474 — 9y

Answer this question