Changing the mouse cursor causes "Rendering paused for debugging"

I have a local script that changes the mouse cursor based on if the player character’s current tool is enabled or not.

local Player = game.Players.LocalPlayer
local Backpack = Player.Backpack

local Mouse = Player:GetMouse()

function ChangeIcon(Reloading)
	
	if Reloading == true then
		Mouse.Icon = "rbxasset://textures/GunWaitCursor.png" --This is where the debugger marks
	else
		Mouse.Icon = "rbxasset://textures/GunCursor.png"
	end

end

PrevTool = nil

Backpack.ChildRemoved:Connect(function(Tool)
	
	ChangedProperty = Tool:GetPropertyChangedSignal('Enabled'):Connect(function()
		ChangeIcon(Tool.Enabled)
	end)
	
	PrevTool = Tool.Name
end)

Backpack.ChildAdded:Connect(function(Tool)
	if Tool.Name == PrevTool then
		ChangedProperty:Disconnect()
		PrevTool = nil
	end
end)

I don’t understand why its upset, as it doesn’t give an error in the console

Wsp Dev, Try This:

local Player = game.Players.LocalPlayer
local Backpack = Player.Backpack
local Mouse = Player:GetMouse()

local toolConnections = {}

function ChangeIcon(Reloading)
    if Reloading then
        Mouse.Icon = "rbxasset://textures/GunWaitCursor.png"
    else
        Mouse.Icon = "rbxasset://textures/GunCursor.png"
    end
end

Backpack.ChildRemoved:Connect(function(Tool)
    if toolConnections[Tool] then
        toolConnections[Tool]:Disconnect()
        toolConnections[Tool] = nil
    end
end)

Backpack.ChildAdded:Connect(function(Tool)
    if not Tool:IsA("Tool") then return end
    
    toolConnections[Tool] = Tool:GetPropertyChangedSignal('Enabled'):Connect(function()
        ChangeIcon(not Tool.Enabled)
    end)
    
    ChangeIcon(not Tool.Enabled)
end)

this causes the same issue, except it happens when the tool is put away rather than when its taken out

Try this.

local Player = game.Players.LocalPlayer
local Backpack = Player.Backpack
local Mouse = Player:GetMouse()

local toolConnections = {}

function ChangeIcon(Reloading)
    if Reloading then
        Mouse.Icon = "rbxasset://textures/GunWaitCursor.png"
    else
        Mouse.Icon = "rbxasset://textures/GunCursor.png"
    end
end

Backpack.ChildRemoved:Connect(function(Tool)
    local connection = toolConnections[Tool]
    if connection then
        connection:Disconnect()
        toolConnections[Tool] = nil
    end
end)

Backpack.ChildAdded:Connect(function(Tool)
    if not Tool:IsA("Tool") then return end
    
    local connection = Tool:GetPropertyChangedSignal('Enabled'):Connect(function()
        ChangeIcon(not Tool.Enabled)
    end)
    
    toolConnections[Tool] = connection
    ChangeIcon(not Tool.Enabled)
end)

This makes the rendering paused screen come up as soon as i playtest, marking the empty space between ChangeIcon and the Backpack.ChildRemoved as the issue

Perhaps the script is trying to access Tool.Enabled before checking if it was loaded correctly.

local Player = game.Players.LocalPlayer
local Backpack = Player.Backpack
local Mouse = Player:GetMouse()

local currentToolConnection = nil

local function ChangeIcon(reloading)
    Mouse.Icon = reloading 
        and "rbxasset://textures/GunWaitCursor.png" 
        or "rbxasset://textures/GunCursor.png"
end

local function HandleTool(tool)
    if currentToolConnection then
        currentToolConnection:Disconnect()
        currentToolConnection = nil
    end

    if tool and tool:IsA("Tool") then
        local function UpdateIcon()
            ChangeIcon(not tool.Enabled)
        end
        
        currentToolConnection = tool:GetPropertyChangedSignal("Enabled"):Connect(UpdateIcon)
        UpdateIcon()
    else
        ChangeIcon(false)
    end
end

Backpack.ChildAdded:Connect(function(tool)
    HandleTool(tool)
end)

Backpack.ChildRemoved:Connect(function(tool)
    if currentToolConnection and tool:IsA("Tool") then
        HandleTool(nil)
    end
end)

HandleTool(Player.Character and Player.Character:FindFirstChildOfClass("Tool"))

Or you are putting breakpoints in the script.

There are no breakpoints in the script right? . - .

Maybe, maybe he put switches in the script.

I fixed it by instead checking the player’s character for a tool being added or removed rather than the backpack:

local Player = game.Players.LocalPlayer
local Character = Player.Character

local Mouse = Player:GetMouse()

local DefaultIcon = Mouse.Icon

function ChangeIcon(Value)
	
	print(Value)

	if Value == false then
		Mouse.Icon = "rbxasset://textures/GunWaitCursor.png"
	else
		Mouse.Icon = "rbxasset://textures/GunCursor.png"
	end

end

PrevTool = nil
Connection = nil

Character.ChildAdded:Connect(function(child)
	if child:IsA('Tool') then
		
		Mouse.Icon = "rbxasset://textures/GunWaitCursor.png"
		
		PrevTool = child
		Connection = child:GetPropertyChangedSignal('Enabled'):Connect(function()
			ChangeIcon(child.Enabled)
		end)
		
	end
end)

Character.ChildRemoved:Connect(function(child)
	if child:IsA('Tool') then
		if child == PrevTool then
			Connection:Disconnect()
			PrevTool = nil
		end
		Mouse.Icon = DefaultIcon
	end
end)

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