I’m trying to make a light that will track a player when they’re in a certain zone which is shown by a part, I’m doing this by changing the cframe position to where to face the player. I may be doing this wrong because I’ve never used cframe before. The light faces the player but then rotates differently when it runs again, not sure why it does this though.
local holder = script.Parent.Parent.MACAura2.Holder
local main = script.Parent.Parent.MACAura2.Main
local part = holder.PrimaryPart
local basepart = script.Parent
function onPartTouched(hit)
if hit.Parent:findFirstChild("Humanoid") then
local startPos = part.Position
print("1")
local torso = hit.Parent:findFirstChild("Torso")
local endpos = torso.Position
print("2")
--part.CFrame = CFrame.new(startPos, endpos);
main:SetPrimaryPartCFrame(main:GetPrimaryPartCFrame()*CFrame.fromOrientation(-0.18, math.rad(part.Position.Y), 180))
print("3")
end
end
basepart.Touched:Connect(onPartTouched)
The link sends me to a 404 page and I have 1 part to sense if the player is in the zone, if the player is in the zone then the light should change to look at the player’s torso.
CFrame | Roblox Creator Documentation .lookAt
Sorry, I added the .lookAt after the link and it added it.
I’m guessing the Part you have sensing the player is in the zone has this script in it and that’s what the basepart.Touched does?
Instead of Torso maybe use HumanoidRootPart, Torso is only for R6 players and UpperTorso/LowerTorso is only for R15 Players. All characters have a HumanoidRootPart in them…
also use CFrame.lookAt() as @Scottifly stated!
Quick explanation:
CFrame.lookAt l o o k s A t a part…
2 Arguments are required for this to work.
(Vector3 Position, Vector3 Target or where you want it to look at)
here is my your brand new code;
local holder = script.Parent.Parent.MACAura2.Holder
local main = script.Parent.Parent.MACAura2.Main
local part = holder.PrimaryPart
local basepart = script.Parent
function onPartTouched(hit)
if hit.Parent:findFirstChild("Humanoid") then
local startPos = part.Position
print("1")
main:SetPrimaryPartCFrame(CFrame.lookAt(main:GetPrimaryPartCFrame().Position,hit.Parent.Position)) -- CFrame.Position, did you know? CFrame has psition orientation and other things inside it?
print("3")
end
end
basepart.Touched:Connect(onPartTouched)
do not know if this code works, tell me if u get any errors, sorry if u do ill try and fix them, byeeee
also SetPrimaryPartCFrame and GetPrimaryPartCFrame are only used for models… Normal Part.CFrame are used for parts and other things… ye
The light is in 3 models I think, I might be able to put two of them into blender parts but the one with the lights in might be a bit harder, if this only works for parts, can I do holder:Getchildren then the code for just parts?
Is it ok if maybe… … you can send a screenshot of the Workspace Model? like what it looks like in the workspace! I hope I’m not asking for too much, it would just give me a hint on what you are trying to accomplish with CFrame
I changed my script to something I found on a devforum page to this, it detects it but still fails to move with no errors.
local holder = script.Parent.Parent.MACAura2.Holder
local main = script.Parent.Parent.MACAura2.Main
local part = holder.Hinge
local basepart = script.Parent
function onPartTouched(hit)
if hit.Parent:findFirstChild("Humanoid") then
print("1")
local redBlock = part
local blueCube = hit.Parent:findFirstChild("Head")
-- Create a Vector3 for the target position
local targetPosition = blueCube.Position
-- Point the red block's front surface at 'targetPosition'
redBlock.CFrame = CFrame.new(redBlock.Position, targetPosition)
-- Rotate red block's CFrame relative to itself so that its top surface (not front) points toward the target
local rotatedCFrame = CFrame.Angles(math.rad(-90), 0, 0)
redBlock.CFrame = CFrame.lookAt(redBlock.Position, targetPosition)
end
end
basepart.Touched:Connect(onPartTouched)
Do you have all the light’s Parts Welded together?
Are the welds breaking? You can check them in Test mode.
Check the rotation of the redBlock in Test mode to see if it’s rotating but the other light Model Parts aren’t.
Edit 2: Yeah, dosen’t move, I’ve checked and all the parts are welded, if you know a fix for what is happening in the video then please say cause that’s the closest I’ve got.