I am trying make a moving model using cframe and heartbeat(Makes it smoother) but the problem is it wont stop moving this is the script:
local vehicle = game.Workspace.Robbery.SubmarineExterior
game:GetService("RunService").Heartbeat:Connect(function(dt)
vehicle:SetPrimaryPartCFrame(vehicle.PrimaryPart.CFrame * CFrame.new(-0.1, 0,0 * dt))
wait(10)
vehicle:SetPrimaryPartCFrame(vehicle.PrimaryPart.CFrame * CFrame.new(0,0,0))
end)
blokav
(blokav)
July 17, 2020, 1:10pm
#2
This should stop it from moving after 10 seconds.
local movement = game:GetService("RunService").Heartbeat:Connect(function()
vehicle:SetPrimaryPartCFrame(vehicle.PrimaryPart.CFrame * CFrame.new(-0.1, 0, 0)
end)
wait(10)
movement:Disconnect()
Though if you want it to move a specific distance, or from one specific location to another specific location you should probably use a tween instead.
after it gets disconnected can it wait for certain amount of time then starts moving again?
blokav
(blokav)
July 17, 2020, 1:13pm
#4
Yes you could just repeat that code or wrap it in a loop.
blokav
(blokav)
July 17, 2020, 1:27pm
#6
Sorry, I forgot to add the closing parenthesis for SetPrimaryPartCFrame
still wont work 30 characters…
blokav
(blokav)
July 17, 2020, 1:38pm
#8
Seriously look at the code you posted. You have two connections to RunService.Heartbeat and one of them isn’t needed.
heres the code but still wont work:
local vehicle = game.Workspace.Robbery.SubmarineExterior
local movement = game:GetService("RunService").Heartbeat:Connect(function()
vehicle:SetPrimaryPartCFrame(vehicle.PrimaryPart.CFrame * CFrame.new(-0.1, 0, 0))
end)
wait(10)
movement:Disconnect()
Glitchy4D
(Glitchy)
July 17, 2020, 1:44pm
#10
oh never mind it was because the 0.1
blokav
(blokav)
July 17, 2020, 1:44pm
#11
Are you getting any error messages? What is the context of this script? Is vehicle
being found and does it have a PrimaryPart? “It doesn’t work” isn’t useful at all because there is nothing wrong with the syntax of the code.
Edit: Sorry, haven’t realized you already solved it.
Glitchy4D
(Glitchy)
July 17, 2020, 1:45pm
#12
sorry 0.1 was too small as a number for the model