#RunService Bugs out when I press Record
13 messages · Page 1 of 1 (latest)
I have a script which moves a model every time connected to a runservie:heartbeat() event and when I press F12 to hit record the frame drop bugs out the model move path
and completely breaks where its supposed to actually go
try put a task.wait()
Its probably because you its repeating without a time, like 0.001(Repeated), 0.0001(Repeated again)
Its to much fast to studio
task wait on what
what function
the runservice one?
game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
for _, npc in ipairs(game.Workspace.TowerDefense.Test.Mobs:GetChildren()) do
local distance = (game.Workspace.TowerDefense.Test.Path[npc.Settings.GoalNode.Value].Position - npc:GetPivot().Position).Magnitude
if distance < 0.5 then
if npc.Settings.GoalNode.Value ~= #game.Workspace.TowerDefense.Test.Path:GetChildren() then
npc.Settings.CurrentNode.Value = npc.Settings.CurrentNode.Value + 1
npc.Settings.GoalNode.Value = npc.Settings.GoalNode.Value + 1
npc:PivotTo(CFrame.new(game.Workspace.TowerDefense.Test.Path[npc.Settings.CurrentNode.Value].Position, game.Workspace.TowerDefense.Test.Path[npc.Settings.GoalNode.Value].Position))
else
print("DONE!")
npc:Destroy()
end
else
npc:PivotTo(npc:GetPivot() + npc:GetPivot().LookVector * 20 * deltaTime)
end
end
end)
here's the function for reference
game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
task.wait()
for _, npc in ipairs(game.Workspace.TowerDefense.Test.Mobs:GetChildren()) do
local distance = (game.Workspace.TowerDefense.Test.Path[npc.Settings.GoalNode.Value].Position - npc:GetPivot().Position).Magnitude
if distance < 0.5 then
if npc.Settings.GoalNode.Value ~= #game.Workspace.TowerDefense.Test.Path:GetChildren() then
npc.Settings.CurrentNode.Value = npc.Settings.CurrentNode.Value + 1
npc.Settings.GoalNode.Value = npc.Settings.GoalNode.Value + 1
npc:PivotTo(CFrame.new(game.Workspace.TowerDefense.Test.Path[npc.Settings.CurrentNode.Value].Position, game.Workspace.TowerDefense.Test.Path[npc.Settings.GoalNode.Value].Position))
else
print("DONE!")
npc:Destroy()
end
else
npc:PivotTo(npc:GetPivot() + npc:GetPivot().LookVector * 20 * deltaTime)
end
end
end)
try this
** You are now Level 4! **