local tool = script.Parent
local range = script.Parent.Parent.Stats.range.Value
local damage = script.Parent.Parent.Stats.damage
local Bullet = Instance.new("Part", workspace)
local ShootSpeed = script.Parent.Parent.Stats.shootspeed.Value
local Sound = script.Parent.Sound
local Radius = Instance.new("Part", workspace)
local TestEvent = game.ReplicatedStorage.Events.TestEvent
local ClosestEnemy = tool.Parent.Stats.ClosestEnemy
local Rotate = 3
Radius.CanCollide = true
Radius.Parent = tool
Radius.Position = tool.Parent["Left Leg"].Position
Radius.Position = Radius.Position + Vector3.new(-3,0.025,0)
Radius.CanCollide = false
Radius.Anchored = true
Radius.Size = Vector3.new(10,0,10)
Radius.Name = "MinigunRadius"
function shoot()
Bullet.Transparency = 0
Bullet.CanCollide = true
Bullet.Position = script.Parent.Handle.Position
Bullet.Anchored = true
Bullet.Name = "MiniGun1Bullet"
Bullet.BrickColor = BrickColor.new("New Yeller")
Bullet.TopSurface = Enum.SurfaceType.Smooth
Bullet.BottomSurface = Enum.SurfaceType.Smooth
Bullet.Size = Vector3.new(0.3,0.1,0.1)
Bullet.Orientation = Vector3.new(0, 90, 0)
Bullet.Parent = tool
for yes = 1,range do
wait()
local function closestEnemyFunction()
ClosestEnemy.Value = tool.Parent:GetChildren(CFrame.Angles(ClosestEnemy.torso.Orientation))
end
TestEvent.Event:Connect(closestEnemyFunction)
if Rotate == 1 then
Bullet.Position = Bullet.Position + Vector3.new(0,0,-1)
end
if Rotate == 2 then
Bullet.Position = Bullet.Position + Vector3.new(0,0,1)
end
if Rotate == 3 then
Bullet.Position = Bullet.Position + Vector3.new(-1,0,0)
end
if Rotate == 4 then
Bullet.Position = Bullet.Position + Vector3.new(1,0,0)
end
end
Bullet.Transparency = 1
Bullet.CanCollide = false
end
while wait(ShootSpeed) do
Sound:Play()
shoot()
end
Script for the zombie
FastZombie = script.Parent
local TestEvent = game.ReplicatedStorage.Events.TestEvent
function onTouched(hit)
if (hit.Name == "MinigunRadius") then
print('touched minigun radius')
local NameValue = Instance.new("StringValue", game.Workspace.Minigunner.Stats)
NameValue.Name = 'ClosestEnemy'
NameValue.Value = FastZombie.Torso.Orientation
TestEvent:Fire(workspace.Minigunner.Tazer.Script)
end
end
connection = FastZombie.Touched:connect(onTouched)
That stopped the error, but the minigunner is still standing still
local function closestEnemyFunction()
ClosestEnemy.Value = tool.Parent:GetChildren(CFrame.Angles(ClosestEnemy.torso.Orientation))
end
TestEvent.Event:Connect(closestEnemyFunction)
and it doesnât print âtouched minigun radiusâ in this
if (hit.Name == "MinigunRadius") then
print('touched minigun radius')
local NameValue = Instance.new("StringValue", game.Workspace.Minigunner.Stats)
For the top script, not sure what youâre accomplishing there, but GetChildren doesnât need any arguments, just :GetChildren() as is.
For the second script, the way hit works in a Touched function is that it returns the part that it detects touching. So for a player it can be a Left Arm or a Right Arm and so forth.
local function closestEnemyFunction()
end
TestEvent.Event:Connect(closestEnemyFunction)
I am trying to get the npc (minigunner) to look at the closest zombie (the one that touches the radius from this script) the problem is I have no clue how to do that, so I was trying to make the zombie create a string value when it touches the radius, and then the minigunner would look at the one that touched it.
FastZombie = script.Parent
local TestEvent = game.ReplicatedStorage.Events.TestEvent
function onTouched(hit)
if (hit.Name == "MinigunRadius") then
print('touched minigun radius')
local NameValue = Instance.new("StringValue", game.Workspace.Minigunner.Stats)
NameValue.Name = 'ClosestEnemy'
NameValue.Value = FastZombie.Torso.Orientation
TestEvent:Fire()
end
end
connection = FastZombie.HumanoidRootPart.Touched:connect(onTouched)
This snippet of code means that if the touched brick is named âMinigunRadiusâ, which most of the time it wonât, then it will do the code below it. To detect if it is a zombie, first you need to check if the Parent of the part has a Humanoid (hit.Parent:FindFirstChild).
If it finds it, you can check if the zombie is indeed a zombie (maybe a boolvalue on them), if it is, it will fire the event, where it would focus on the target.
FastZombie = script.Parent
local TestEvent = game.ReplicatedStorage.Events.TestEvent
function onTouched(hit)
if (hit.Parent.Parent.Name == "Minigunner") then
print('touched minigun radius')
local NameValue = Instance.new("StringValue", game.Workspace.Minigunner.Stats)
NameValue.Name = 'ClosestEnemy'
NameValue.Value = FastZombie.Torso.Orientation
TestEvent:Fire()
end
end
connection = FastZombie.HumanoidRootPart.Touched:connect(onTouched)
Almost, you donât need the extra .Parent for the NPC, otherwise, depending where itâs located, it would come out as if itâs comparing Workspace to Minigunner (aka if "workspace" == "Minigunner then)
Ok, so for the top script would it be something like this?
(Sorry for asking so many questions, I am still new to scripting and this is just a huge thing that is breaking the game)
local function closestEnemyFunction()
local ClosestEnemy = tool.Parent.Stats.ClosestEnemy
script.Parent.Parent.Torso.Orientation = ClosestEnemy.Orientation
end
TestEvent.Event:Connect(closestEnemyFunction)
That might not work since the orientation of the NPC would be the same as the target, making it seem like itâs facing away from the target. Also, from my experience, it would only rotate the torso.