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

How do I make my gun bot say something once when he spots a target?

Asked by
Stea_my 48
4 years ago

I'm using a gun bot kit (for reference heres the kit im using: https://web.roblox.com/library/303318308/AI-Bots) and I made it so when it sees a player it says "Target spotted." but it just keeps saying it over and over and over, heres the part where it spots somebody, and tell me how I can fix it if you know.

local function near()
    local dis,pl=50,nil
    for _,v in ipairs(game.Players:GetPlayers())do
        if v.Character and v.Character:FindFirstChild'Humanoid'and v:DistanceFromCharacter(h.Position)<dis then
game:GetService("Chat"):Chat(script.Parent.Head, "Target Spotted.", Enum.ChatColor.White) -- the part thats messing up
            dis,pl=v:DistanceFromCharacter(h.Position),v
        end
    end
    if pl then
        return pl.Character:GetModelCFrame(),dis,CFrame.new(pl.Character.Humanoid.WalkToPoint).lookVector
    else
        return nil
    end
end

Answer this question