Code isnt executing - RunService

i am making a simple math animation using the sin() function in a RunService.HeartBeat connection

Main Code
CoinModel.Model:SetAttribute("etime", 0)
CoinModel.Model:SetAttribute("LastPos", CoinModel.Model.Position)

RunService.Heartbeat:Connect(function(deltaTime: number)
	local eTime = CoinModel.Model:GetAttribute("etime") + deltaTime
	local BasePos = CoinModel.Model:GetAttribute("LastPos")
			
	CoinModel.Model:SetAttribute("etime", eTime)
			
	local OffSet = math.sin(eTime * 2) * 3
	local RotateOffSet = eTime * 1
			
	CoinModel.Model.CFrame = CFrame.new(BasePos.X, BasePos.Y * OffSet, BasePos.Y) * CFrame.Angles(0, RotateOffSet, 0)
end)

Math animation code seems correct, however there could be 2 reasons why it doesn’t execute.
1st reason: Script doesn’t connect event properly, you need to make sure it does connect function to RunService.Heartbeat, if it is not got connected during runtime, you should debug your code and find reason why.
2nd reason: RunService.Heartbeat fires connected function to it, however it moves and rotates CoinModel.Model (I assume it is a Part instance) via CFrame property and for example this part CoinModel.Model is actually invisible and acts as CoinModel.PrimaryPart, which means without proper welding it will not move or rotate other BaseParts (for example coin mesh) unless they were welded for example with WeldConstraint.
Anyway it is hard to say exactly why it doesn’t executes unless you provide more information (such as code or coin model hierarchy).

  1. the RunService.HeartBeat does execute but it wont execute that part of code for some reason
  2. the CoinModel.Model is a mesh so i swapped it with a BasePart but no effect

Coin hierarchy

Prints just fine.

Alright so it runs and rotates actual MeshPart, I assume the problem might be inside CoinSpawnHandler script (I don’t really think that workspace instances affect this behavior), so could you please provide its content or just function in which event gets connected?

your script seems to work just fine, if i were you, id print out the coinmodel and ensure its not using the template

I also think that this is the problem, but we cannot judge without the content of the script. Seems like CoinModel keeps cloning but CFrame changes on original MeshPart but not on clones.

Try swap RunService.Heartbeat to RunService.Stepped or RunService.PreSimulation Make connection and print it, also i dont recommend use attributes in RunService for perfomance reasons

You are right!, i was unknowing editing the Original model instead of the clone :sweat_smile:
but its works now!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.