I need help with a script to make a part face the mouse, I alredy have the position of the mouse in a 3d space every step, I Have looked for Way too much time and I am desperate, ive always found the same three anwsers, but also There is one of them that might work, it didnt work before because I couldnt get the mouse position every frame, but im not sure if it will work now either
local debounce = false
local cooldown = 2
script.Parent.Activated:Connect(function()
if debounce == false then
spawn(function()
debounce = true
local GB = script.Parent.GasterBlaster:Clone()
GB.Parent = workspace
spawn(function()
GB:SetPrimaryPartCFrame(script.Parent.Parent.HumanoidRootPart.CFrame * CFrame.new(3, 3, 0))
end)
local MousePos = script.Parent:WaitForChild("gg").Value
GB.PrimaryPart.CFrame = CFrame.lookAt(GB.PrimaryPart.Position, MousePos)
GB:WaitForChild("Destroy").Disabled = false
GB:WaitForChild("Shoot").Disabled = false
GB:WaitForChild("Creator").Value = script.Parent.Parent
wait(cooldown)
debounce = false
end)
end
end)
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
local part = --Your part here
while task.wait() do
part.CFrame = CFrame.lookAt(part.Position,mouse.Hit)
end
Well it look like you have it right, you’re setting the GB’s primary part.CFrame to CFrame.lookAt so it should work, can you maybe post a screenshot of it?
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
local part = workspace.Part --Your part here
while task.wait() do
part.CFrame = CFrame.lookAt(part.Position,mouse.Hit)
end
This is for a model.
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
--local part = workspace.Part --Your part here
local model = workspace.Model
while task.wait() do
model:PivotTo(CFrame.lookAt(model.PrimaryPart.Position,mouse.Hit.Position))
end
i do have a localscript that sends the information to a vector3 value, here it is:
local players = game:GetService("Players")
local runService = game:GetService("RunService")
local client = players.LocalPlayer
local mouse = client:GetMouse()
local tool = script.Parent
local value = tool:WaitForChild("gg")
local equipped = false
game:GetService("RunService").RenderStepped:Connect(function()
if equipped then
value.Value = mouse.Hit.Position
end
end)
tool.Equipped:Connect(function()
equipped = true
end)
tool.Unequipped:Connect(function()
equipped = false
end)
local players = game:GetService("Players")
local runService = game:GetService("RunService")
local client = players.LocalPlayer
local mouse = client:GetMouse()
local tool = script.Parent
local value = tool:WaitForChild("gg")
--local remoteF = tool.RemoteEvent
local remoteF = workspace.Model.RemoteEvent
local equipped = false
game:GetService("RunService").RenderStepped:Connect(function()
if equipped then
value.Value = mouse.Hit.Position
remoteF:FireServer(value.Value)
end
end)
tool.Equipped:Connect(function()
equipped = true
end)
tool.Unequipped:Connect(function()
equipped = false
end)
i think theres a misunderstanding here, i need it to look to the mouse when clicked, and not continously, now of course, this is still useful for another idea i had, so thank you for that
oh, no, no, i didnt mean making it face the mouse when you have a tool, the tool makes the part appear and shoot, you need the mouse to aim, thats where we were wrong, but i think this will help me either way