Will this code cause preformance problems?

Basically, I am making an adventure game and I need coins.
I coded the rotation of the coins using the runservice.Heartbeat event

Here is the code:

--scripted by supermanover00

local runservice = game:GetService("RunService")

local coin = script.Parent
local taken = coin:WaitForChild("Taken")
local remoteevent = game.ReplicatedStorage:WaitForChild("RemoteEvent")

local debounce = true
local respawntime = 180

local function onTouched(part)
	local player = game.Players:GetPlayerFromCharacter(part.Parent)
	local humanoid = part.Parent:FindFirstChild("Humanoid")
	if debounce and player and humanoid and humanoid.Health > 0 then
		debounce = false
		coin.Transparency = 1
		player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1
		wait(respawntime)
		debounce = true
		coin.Transparency = 0
	end
end

local function rotateLoop()
	coin.Orientation = coin.Orientation + Vector3.new(0,4,0)
end

coin.Touched:connect(onTouched)
runservice.Heartbeat:connect(rotateLoop)

I am basically just wondering if this will give the game substantial issues if I have this coded inside every single coin (and there will be loads).
Thanks!

You should not be using connect instead of Connect, else I would say use this function instead of roateLoop:

local function rotateLoop()
    coin.CFrame = coin.CFrame * CFrame.Angles(0,4,0)
end
1 Like

What is the difference between connect and Connect? It’s the exact same as far as I know.

connect is deprecated and should be not used.

I have used it since 2015… Damn

1 Like

But why should CFrame get used here instead? I am sorry if I’m asking a lot, but I really need to know this.

CFrame is giving you more power over position, rotation and more.

1 Like

Ok thanks, I just didn’t use it here because I had no intention to edit position. Thanks a lot for your feedback! I will keep it in mind. :slight_smile:

I believe it would be fine either way as CFrame is just more useful even when doing only orientation but orientation would affect CFrame anyways so it wouldn’t matter.