Hi guys. I have a minor issue. I’ve been trying to make this homing object chase the player while spinning. And although the object does chase the player, it does not spin! Please, if you can help me, I will appreciate it a lot, and consider your solution box checked.
What do you want to achieve? A homing object that chases the player but also spins.
What is the issue? It chases the player, but it does not spin.
What solutions have you tried so far? I’ve tried changing the CFrame multiple times, even switching to TweenService. It did not work.
Here is the code I have. I’m using AlignOrientation since that is the most up to date method when it comes to orienting parts with attachments and so on.
bin = script.Parent
bin.Damage.Disabled = false
bin.Anchored = false
local Players = game.Players or game:GetService("Players")
local Teams = game.Teams
local Debris = game:GetService("Debris")
Debris:AddItem(bin, 6)
bin.Parent.Alert:Play()
task.wait(2)
function move(target)
local dir = (target.Position - bin.Position).Unit
local spawnPos = bin.Position
local pos = spawnPos + (dir * 1)
-- ISSUE IS RIGHT HERE!! I think...
bin:findFirstChild("AlignOrientation").CFrame = CFrame.new(bin.AlignOrientation.CFrame.Position+Vector3.new(0, 8, 0), pos+Vector3.new(0, 0, 8) + dir)
bin:findFirstChild("AlignOrientation").MaxTorque = math.huge
end
function moveTo(target)
bin.AlignPosition.Position = target.Position
bin.AlignPosition.MaxForce = math.huge * bin.Speed.Value
end
function findNearestTorso(pos)
local list = game.Workspace:GetChildren()
local torso = nil
local dist = math.huge
local temp = nil
local human = nil
local temp2 = nil
for x = 1, #list do
temp2 = list[x]
if (temp2.className == "Model") and (temp2 ~= script.Parent) then
temp = temp2:findFirstChild("HumanoidRootPart")
human = temp2:findFirstChild("Humanoid")
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) and Players:GetPlayerFromCharacter(temp.Parent) then
local Player = Players:GetPlayerFromCharacter(temp.Parent)
if (temp.Position - pos).Magnitude < dist and Player.Team == Teams.Chara then
torso = temp
dist = (temp.Position - pos).Magnitude
end
end
end
end
return torso
end
while true do
local torso = findNearestTorso(bin.Position)
if torso~=nil then
move(torso)
moveTo(torso)
end
wait()
end
Sorry if the script is a little messy. It’s not mine, and I just added some extra touches to it.
I would try changing the MaxTorque to a lower number, as setting it to basically infinity could cause it to spin so fast that becomes invisible. Try something like 100 or 1000.
If that doesn’t work, can you please show what the AlignOrientation and its attachments look like?
Use RemoteEvent to make all clients to rotate your object.
On how to fire the RemoveEvent is :
YourRemoteEvent:FireAllClients(WHERE_YOU_STORE_THE_OBJECT) --fire all clients to spin your object
the LocalScript one is:
-- Put this script inside of StarterPlayerScripts
local ReplicatedStorage = game.ReplicatedStorage
local RunService = game:GetService("RunService")
local YourRemoteEvent = ReplicatedStorage:FindFirstChild("YourRemoteEvent")
local PerRotation, HowSmooth = 15, .15
local Object
local RotateObject = false
YourRemoteEvent.OnClientEvent:Connect(function(object)
Object = object
RotateObject = true
end)
RunService.RenderStepped:Connect(function()
if RotateObject ~= false then
local final = Object.CFrame * CFrame.Angles(math.rad(PerRotation),0,0) -- You can tweak it if it doesn't rotate the way you wanted
Object.CFrame = Object.CFrame:Lerp(final, HowSmooth)
end
end)
Okay. Here are the properties. (Not images, because the window sadly isn’t big enough.)
– AlignmentMode: One Attachment.
– AlignOrientation: PrimaryAxisOnly is unchecked, ReactionTorqueEnabled is unchecked, RigidityEnabled is unchecked.
– MaxAngularVelocity is infinite.
– MaxTorque is 10,000, but the script changes it to infinite.
– Responsiveness is 200 (Maximum limit)
– TargetOrientation (Not used, but here are the properties anyway.): PrimaryAxis (1, 0, 0), SecondaryAxis (0, 1, 0)