Script wont work correctly

Im trying to make a searchlight beam that rotates around and you die if it catches you, and the model above it rotates around in circles (which works perfectly fine at the moment, its the searchlight attached to the model that isnt working)

This script should change the position to the motor’s parent’s (block) position and then rotate. However when i run this in a game or test it, it just flies off into the distance and i am so confused.

Some solutions i have tried are using Orientation, but when i do that roblox simply stops the script at 89,0,0 and then starts freaking out by jumping from 90,0,0 to 89,0,0, so that did not work. Im wondering if anyone can find the issue?

I’ve also changed the wait time to () and used task.wait, but neither of those fix my issue of the model flying into the distance.

This exact code i have used in another game before but it just now stopped working.

Can someone help me? because im stumped here.

while true do
	script.Parent.Position = script.Parent.Parent.Position
	script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0,-0.005 ,0)
	wait(0.01)
end

structure (How the blocks are sorted in explorer)
Part
–MotorPart
----Script
I dont know if that helps at all, but i’ll still put it here.

I can attach videos of how the model behaves if needed.

1 Like

Have you ever tried removing the collision of the MotorPart?

Also, I got a better version of your code:

local RunService = game:GetService("RunService")

local speed = 0.005 * 100 -- that 100 comes from your wait(0.01) function, as it is 100 times a second, 0.01 * 100 = 1

RunService.Heartbeat:Connect(function(dt)
	script.Parent.Position = script.Parent.Parent.Position
	script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0, speed * -dt ,0)
end)
1 Like

Yes it has no collision already.

Your script improves the drifting of the beam to the model but it still drifts

I found the problem. When moving, the welded spotlight does not move with the motor causing it to drift. Thanks for your help

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.