So I’m fixing the minecart follow script, but everytime I try, it doesn’t work.
So that’s why I made this topic.
Here’s the minecart script
local tweenservice = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(0.2, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
local snapevent = game.ReplicatedStorage.Events.SnapCameraToHead
local fallout = true
game.ReplicatedStorage.Events.MinecartStart.OnServerEvent:Connect(function(player, track)
local waypoints = track.Waypoints
local minecart = script.Parent:Clone()
minecart.Parent = workspace
local mover = minecart.Mover
local humanoid = player.Character.Humanoid
local notleananim = script.NotLean
local leanleftanim = script.LeanLeft
local leanrightanim = script.LeanRight
local notlean = humanoid.Animator:LoadAnimation(notleananim)
local leanleft = humanoid.Animator:LoadAnimation(leanleftanim)
local leanright = humanoid.Animator:LoadAnimation(leanrightanim)
local ragdollevent = game.ReplicatedStorage.Events:WaitForChild("Ragdoll")
print(minecart.Camera)
snapevent:FireClient(player, true, minecart.Camera)
mover.Anchored = true
notlean:Play()
local connection = humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
if math.round(humanoid.MoveDirection.X) == -1 then
--leans to the left
leanright:Stop()
notlean:Stop()
leanleft:Play()
minecart.Sounds.LEAN:Resume()
minecart:SetAttribute("Lean", "Left")
elseif math.round(humanoid.MoveDirection.X) == 1 then
--leans to the right
notlean:Stop()
leanleft:Stop()
leanright:Play()
minecart.Sounds.LEAN:Resume()
minecart:SetAttribute("Lean", "Right")
else
--doesnt lean
leanright:Stop()
leanleft:Stop()
notlean:Play()
minecart.Sounds.LEAN:Pause()
minecart:SetAttribute("Lean", "NotLeaning")
end
end)
minecart.Sounds.Minecart:Play()
print(track)
print(player)
local weld = Instance.new("Weld")
weld.Parent = workspace
weld.Part0 = minecart.Seat
weld.Part1 = player.Character.HumanoidRootPart
for waypoint = 1, #waypoints:GetChildren() do
local moveToWaypoint = tweenservice:Create(mover, tweeninfo, {CFrame = waypoints[waypoint].CFrame})
moveToWaypoint:Play()
moveToWaypoint.Completed:Wait()
end
leanright:Stop()
leanleft:Stop()
notlean:Stop()
weld:Destroy()
minecart.Sounds.Minecart:Stop()
connection:Disconnect()
minecart.Sounds.LEAN:Stop()
minecart:SetAttribute("Lean", nil)
snapevent:FireClient(player, false)
if fallout == true then
ragdollevent:FireClient(player, 3)
mover.Anchored = false
end
end)
And this is the camera script.
local tweenservice = game:GetService("TweenService")
local debounce = false
game.ReplicatedStorage.Events.SnapCameraToHead.OnClientEvent:Connect(function(switch, camerapart)
print(camerapart)
if switch == true then
debounce = false
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
repeat
task.wait()
if not debounce then
local smoothtransition = tweenservice:Create(workspace.CurrentCamera, TweenInfo.new(0.08, Enum.EasingStyle.Cubic, Enum.EasingDirection.InOut), {CFrame = camerapart.CFrame})
smoothtransition:Play()
end
until switch == false
elseif switch == false then
debounce = true
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
end
end)