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

Why does this code not work and how would i check the players team?

Asked by
Puppynniko 1059 Moderation Voter
2 years ago

local part = script.Parent local Shot = script.Parent.Parent.ShotPart local firerate = 0 local dmg = 100 local speed = 170 local range = 1000 local db = true local rep = game.ReplicatedStorage:WaitForChild("TeamEvent") --[[local targets = { game.Workspace.Model:GetDescendants():GetDescendants() }]] local lookvector = part.CFrame.LookVector while db == true do local target = nil for i,v in pairs(game.Workspace:getChildren()) do local player = game:GetService("Players") local maths = math.random(1,4) local hum = v:FindFirstChild("Humanoid") local ignore = v:FindFirstChild("Pirate") local ignore1 = v:FindFirstChild("Navy") if script.Parent.Neutral == true and script.Parent.Cap.Value == BrickColor.new("Medium stone grey") then local targets = v:FindFirstChild("Torso") if hum and targets and hum.Health > 0 then if (targets.Position - Shot.Position).Magnitude < range then local ray = Ray.new(Shot.Position,(targets.Position - Shot.Position).Unit * range) local hit, Pos = game.Workspace:FindPartOnRayWithIgnoreList(ray, {Shot, part}) if hit == targets then target = targets db = false else print("some thing is in the way") end end end elseif script.Parent.Neutral == false and script.Parent.Cap.Value == BrickColor.new("Lapis") then local targets = v:FindFirstChild("Pirate") if hum and targets and hum.Health > 0 then if (targets.Position - Shot.Position).Magnitude < range then local ray = Ray.new(Shot.Position,(targets.Position - Shot.Position).Unit * range) local hit, Pos = game.Workspace:FindPartOnRayWithIgnoreList(ray, {Shot, part}) if hit == targets then target = targets db = false else print("Pirate") end end end elseif script.Parent.Neutral == false and script.Parent.Cap.Value == BrickColor.new("Really black") then local targets = v:FindFirstChild("Navy") if hum and targets and hum.Health > 0 then if (targets.Position - Shot.Position).Magnitude < range then local ray = Ray.new(Shot.Position,(targets.Position - Shot.Position).Unit * range) local hit, Pos = game.Workspace:FindPartOnRayWithIgnoreList(ray, {Shot, part}) if hit == targets then target = targets db = false else print("navy") end end end end end if target then local targets = target part.CFrame = CFrame.new(part.Position, targets.Position) local ball = game.ServerStorage:WaitForChild("Ball") local cloneball = ball:Clone() cloneball.Position = Shot.Position cloneball.Parent = game.Workspace cloneball.Velocity = part.CFrame.LookVector*speed cloneball.Touched:Connect(function(ObjectHit) local hum = ObjectHit:FindFirstChild("Humanoid") local explosion = Instance.new("Explosion") explosion.BlastRadius = 10 explosion.ExplosionType = Enum.ExplosionType.Craters -- damages terrain explosion.Position = ObjectHit.Position explosion.Parent = game.Workspace cloneball:Destroy() if hum then hum.Health = dmg end end) wait(0.5) db = true end --[[local hit, position = game.Workspace:FindPartOnRayWithIgnoreList(ray, {part}) if hit then end]] wait(0.5) end

how do i make it not to shoot team mates instead shoot enemy's rn it wont work and i dont know what to do and if there is a more better way of doing this

elseif script.Parent.Neutral == false and script.Parent.Cap.Value == BrickColor.new("Lapis") then
            local targets = v:FindFirstChild("Pirate")
            if hum and targets and hum.Health > 0 then
                if (targets.Position - Shot.Position).Magnitude < range then
                    local ray = Ray.new(Shot.Position,(targets.Position - Shot.Position).Unit * range)
                    local hit, Pos = game.Workspace:FindPartOnRayWithIgnoreList(ray, {Shot, part})
                    if hit == targets then
                    target = targets
                    db = false
                    else
                    print("Pirate")
                    end
                end
            end

Answer this question