I am making cursor style for my game and when it detects a given heartbeat value, it switches the icon to a loading one, but that one does not load, leading to this:
local mouse = game.Players.LocalPlayer:GetMouse()
while true do
wait()
local Heartbeat = game:GetService("RunService").Heartbeat:Wait()
if Heartbeat >= 0.016 then
mouse.Icon = "http://www.roblox.com/asset/?id=15648791102"
else
mouse.Icon = "http://www.roblox.com/asset/?id=15648431915"
end
end
local mouse = game.Players.LocalPlayer:GetMouse()
while true do
wait()
local Heartbeat = game:GetService("RunService").Heartbeat:Wait()
if Heartbeat >= 0.016 then
mouse.Icon = "rbxassetid://15648791102"
else
mouse.Icon = "rbxassetid://15648431915"
end
end
Instead of using game:GetService("RunService").Heartbeat:Wait() , you should connect to the Heartbeat event.
local mouse = game.Players.LocalPlayer:GetMouse()
local RunService = game:GetService("RunService")
local function updateMouseIcon()
if RunService.Heartbeat >= 0.016 then
mouse.Icon = "http://www.roblox.com/asset/?id=15648791102"
else
mouse.Icon = "http://www.roblox.com/asset/?id=15648431915"
end
end
RunService.Heartbeat:Connect(updateMouseIcon)
while true do
wait()
updateMouseIcon()
end
I’ve created a function called updateMouseIcon that sets the mouse icon based on the Heartbeat value. I then connect this function to the Heartbeat event using RunService.Heartbeat:Connect(updateMouseIcon) . Finally, the updateMouseIcon function is called both within the event handler and outside the loop to ensure the mouse icon is updated continuously.