At this point I’m desperate to get this script working so, any recommendations will help greatly.
This script is meant to make a spotlight model move, more like an actual spotlight. Smooth and realistic. Yet, with my current skills (close to no skill), this is difficult just trying to change an original script I got help with.
(I apologize for this horribly messy script, I need a lot of help)
if not game:IsLoaded() then game.Loaded:Wait() end
local userInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local SpotlightHead = game.Workspace.Spotlight.Arm.Head
local UpdateCon
local moveStart = SpotlightHead:GetPivot()
local moveEnd = moveStart * CFrame.Angles(1, 0, 0)
local tweenInfo = TweenInfo.new(
0.5,
Enum.EasingStyle.Quad,
Enum.EasingDirection.Out,
-1,
true,
0
)
local tweenStart = TweenService:Create(SpotlightHead, tweenInfo, {CFrame = moveEnd})
local tweenStop = TweenService:Create(SpotlightHead, tweenInfo, {CFrame = moveStart})
userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType ~= Enum.UserInputType.Keyboard then return end
if input.KeyCode ~= Enum.KeyCode.KeypadEight then return end
if UpdateCon then
UpdateCon:Disconnect()
UpdateCon = nil
end
UpdateCon = RunService.Heartbeat:Connect(function(dt)
tweenStart:Play()
SpotlightHead:SetPrimaryPartCFrame(moveStart)
end)
end)
userInputService.InputEnded:Connect(function(input, gameProcessedEvent)
if input.UserInputType ~= Enum.UserInputType.Keyboard then return end
if input.KeyCode ~= Enum.KeyCode.KeypadEight then return end
if not UpdateCon then return end
tweenStop:Play()
UpdateCon:Disconnect()
UpdateCon = nil
end)
Currently, there is an error at the time of testing this script:
(just to dumb it down for easier reference, the original script moved the spotlight model abruptly, which didn’t sit right with me, so I wanted to make it so when it started moving (via a keybind) i wanted it to speed up to a number, lets say 1, and when i released, slow it down back to 0, making it feel more smooth)
Here is how it originally looked for reference:
If anyone can provide any possible solution (or give tips to clean up this garbage code), I will genuinely appreciate you, and leave likes on comments that helped.