Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

:LoadCharacter() makes the mouse icon invisible?

Asked by 5 years ago

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

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 1TheNoobestNoob 717 — 5y
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. TheOddyssey 9 — 5y
0
Additionally UserInputService does not exist on the server User#19524 175 — 5y
0
TheOddyssey, i may fix it Animescapetower 10 — 5y
0
Ok and there is however no problem with it when i just tested it in studio and Animescapetower 10 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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!

Ad

Answer this question