Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

:LoadCharacter() makes the mouse icon invisible?

I have a game that uses rounds which utilizes the :LoadCharacter() method. During these rounds, players are given weapons to fight. However, at the end of the round whenever the :LoadCharacter() method is called to end the round and the players respawn while holding a weapon, their mouse icons are invisible. I attempted to fix this using this script:

local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")

		
Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local Humanoid = Character:FindFirstChildOfClass("Humanoid")
		if Humanoid then
			Humanoid.Died:Connect(function()
				UserInputService.MouseIconEnabled = true
			end)
		end
	end)
end)

However, this uses the Humanoid.Died function, which doesn't help me in this situation, and I am unsure on how to go about this while using :LoadCharacter()

I would appreciate any help leading to fixing this!

Thank you

5 comments

0

The code you provided should not work as it's on the client. PlayerAdded is fired before the client scripts are loaded in (in most of the cases.) Therefore you should just do the .CharacterAdded event or so. Do that and post results here

0

I decided to go with this due to your comment. https://www.robloxdev.com/api-reference/event/Player/CharacterAdded and used the "Detecting Player Spawns and Despawns" sample and added in the local UserInputService and set it to true in the onCharacterAdded function. It prints when the player spawns and despawns, however, it still doesn't show the mouse icon.

0

Additionally UserInputService does not exist on the server

0

TheOddyssey, i may fix it

0

Ok and there is however no problem with it when i just tested it in studio and

1 answer

I ended up fixing the problem.

Here is the working code:

local Player = game:GetService("Players").LocalPlayer
local UI = game:GetService("UserInputService")

Player.CharacterAdded:Connect(function(char)
    local Humanoid = char:WaitForChild("Humanoid")
    UI.MouseIconEnabled = true
end)

Thanks to @CodeAddict and @incapaz for the help, I appreciate it!

This discussion is preserved as it was. New answers, comments, and votes are closed.