To the local scripts inside my snipers, I am trying to make it so that when the player reloads, the mouse icon changes to a crosshair with a reloading symbol in the bottom right corner, however, when the player equips the rifle, they are not given the correct mouse icon and are instead given the default mouse icon. This is what the code looks like:
Tool.Equipped:connect(function(TempMouse)
Equipped = true
if Module.AmmoPerClip ~= math.huge then GUI.Parent = plr.PlayerGui end
if IdleAnim then IdleAnim:Play(nil, nil, Module.IdleAnimationSpeed) end
local reloading = plr.Character:FindFirstChild("Reload")
if reloading then
-- successfully prints out when player equips without loading
print("Reloading with Mousereloadicon")
TempMouse.Icon = "rbxassetid://" .. Module.MouseReloadIconID
else
-- successfully prints out when player equips with reloading
print("Normal Mouse icon")
TempMouse.Icon = "rbxassetid://" .. Module.MouseIconID
end
if Module.DualEnabled and not workspace.FilteringEnabled then
Handle2.CanCollide = false
local LeftArm = Tool.Parent:FindFirstChild("Left Arm")
local RightArm = Tool.Parent:FindFirstChild("Right Arm")
if RightArm then
local Grip = RightArm:WaitForChild("RightGrip", 0.01)
if Grip then
Grip2 = Grip:Clone()
Grip2.Name = "LeftGrip"
Grip2.Part0 = LeftArm
Grip2.Part1 = Handle2
Grip2.Parent = LeftArm
end
end
end
local Character = plr.Character
-- only play this if the player is NOT reloading upon equip
if not Character:FindFirstChild("Reload") then
script.ReloadFinish:Play()
end
-- update the mouse icon to the non-reload version, but only if equipped
-- this used to be within global scope but moved inside local scope to access
-- TempMouse. I feel like there is a better solution to this using the globally indexed
-- Mouse from local Mouse = plr:GetMouse(), but none of my iterations were able to
-- successfully use this
toolRepo.Reload.OnClientEvent:Connect(function()
if not Equipped then return end
print("Adding reload Mouse icon")
TempMouse.Icon = "rbxassetid://" .. Module.MouseReloadIconID
end)
end)
The final part, the onclient event, currently does not work, but I will work on fixing that in the next implementation.
All of the prints fire correctly when the player equips the tool, yet the icons do not appear. I have tried swapping ou the ID for MouseIconID to a different decal which miraculously made it work, but the same is not true for MouseReloadIconID.
I had tried using a helper function to reassign the mouseIcon but that didn’t work so I assumed I had to keep things within the scope of the function inside of .Equipped although that didn’t work. Someone suggsted as well that I use “RunService” as such:
RunService.RenderStepped:Connect(function()
if Equipped then
Mouse.Icon = "rbxassetid://" .. Module.MouseIconID
end
end)
Although this did not work either.
Why is this bug happening, and more specifically only with the two images (MouseIconID = 102474617536760, MouseReloadIconID = 123149595999012)? I uploaded them at least an hour ago and have relaunched studio to test with a fresh instance of the engine. Is there potentially a better way of mutating the player’s mouse than the way I am currently handling it?