Hello everyone, lyrnu here. I need some help.
- What do you want to achieve? Keep it simple and clear!
I’m creating a procedurally generated spider and I am looking to add a turret on it’s back that moves to look at the closest player.
-
What is the issue? Include screenshots / videos if possible!
Well… for some reason, (probably because its a rig) when the turrets’ code looks at the nearest player, every other part moves as well. No, the turret isn’t it’s root/primary part. And yes - it’s pretty funny…
Here is the AimCode (scrapped from toolbox(very deprecated but I have tried other scripts and didn’t seem to function whatsoever)) :
function findTorso(pos)
local torso = nil
local dist = 100
local child = workspace:children()
for i=1, #child do
if child[i].className == "Model" then
local h = child[i]:findFirstChild("Humanoid")
if h ~= nil then
local check = child[i]:findFirstChild("Head")
if check ~= nil then
if (check.Position - pos).magnitude < dist then
torso = check
dist = (check.Position - pos).magnitude
end
end
end
end
end
return torso
end
game:GetService("RunService").Stepped:Connect(function()
local torso = findTorso(script.Parent.Position)
if torso ~= nil then
script.Parent.CFrame = CFrame.new(script.Parent.Position, torso.Position)
end
end)
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Yes I did which is why I’m looking for your help. I think @dthecoolest did something on Turrets. Not sure if it works for parts attached as a rig.
Thank you for your time!