Roblox's Scripting Helpers Forum section fixed this.
I have an RCL gun that changes the mouse icon to Gun and GunWait, but when the gun is unequipped, it doesn't set the mouse back to default. How can I fix that?
Here's the script:
local reloadTime = 3 local clipSize = 30 local fireRate = .13 local damage = 10 local spread = 1.35 local range = 999 local ammo = clipSize local teamDamageEnabled = false local serverDamageEnabled = true local hitSoundEnabled = false local cursorNormal = "rbxasset://textures\\GunCursor.png" local cursorReload = "rbxasset://textures\\GunWaitCursor.png" local hitSoundId = "rbxasset://sounds\\metalgrass2.mp3" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- local tool, player = script.Parent, game.Players.LocalPlayer local character, handle, mouseDown, reloading, firing, debris, cframe, vector3, instance, ray, mathRandom, server, body, config, deathCon, serverDmg, pingCon, create = player.Character, tool.Handle, false, false, false, game:GetService("Debris"), CFrame.new, Vector3.new, Instance.new, Ray.new, math.random, workspace:findFirstChild("Server.rbxl"), {Torso, LeftArm ,RightArm, LeftShoulder, RightShoulder}, assert(LoadLibrary("RbxUtility")).Create local create = assert(LoadLibrary("RbxUtility")).Create local weld = instance("Weld") local leftWeld, rightWeld = weld:Clone(), weld:Clone() local hitSound = create("Sound"){SoundId = hitSoundId; Pitch = 1.5; Volume = hitSoundEnabled and 1 or 0} local laserPart = create("Part"){Name = "_B"; FormFactor = 0; BrickColor = player.TeamColor; Anchored = true, CanCollide = false; Locked = true; Size = vector3(1,1,1); TopSurface = 0; BottomSurface = 0} local mesh = create("SpecialMesh"){Parent = laserPart; MeshType = "Brick"; Name = "Mesh"; Scale = vector3(.2, .2, 1)} local creatorTag = create("ObjectValue"){Name = "creator"; Value = player} if tool:findFirstChild("Loaded") then ammo = 0 else local loadedTag = creatorTag:Clone() loadedTag.Name = "Loaded" loadedTag.Parent = tool end serverDmg = serverDamageEnabled and (server and true or false) or false local function raycast(start, finish, ignore) local directionVec = (finish-start).unit local hit, pos = workspace:FindPartOnRayWithIgnoreList(ray(start, directionVec*range), ignore) if hit and pos and hit.Name=="_B" then hit, pos = raycast(pos, directionVec * range, ignore) end return hit, pos end local function fire(aim, mouse) local origin = handle.Position local distance = (origin-aim).magnitude local minSpread, maxSpread = -(spread/100)*distance, (spread/100)*distance local finalAim = vector3((aim.x)+(mathRandom(minSpread, maxSpread)), (aim.y)+(mathRandom(minSpread, maxSpread)), (aim.z)+(mathRandom(minSpread, maxSpread))) local hitPart, hitPos = raycast((player.Character.Head.CFrame * CFrame.new(0.5,0,0)).p, finalAim, {player.Character}) local bulletLength, orientation = (origin-hitPos).magnitude, cframe(origin, hitPos) local laser1, laser2 = laserPart:clone(), laserPart:clone() laser1.CFrame = orientation * cframe(0,0,-bulletLength*.75) laser1.Mesh.Scale = vector3(.2, .2 , bulletLength*.5) laser2.CFrame = orientation * cframe(0,0, -bulletLength*.25) laser2.Mesh.Scale = vector3(.2, .2, bulletLength*.5) laser1.Parent = workspace laser2.Parent = workspace debris:AddItem(laser2, .03) debris:AddItem(laser1, .06) if hitPart then local humanoid = hitPart.Parent:FindFirstChild("Humanoid") or hitPart.Parent.Parent:FindFirstChild("Humanoid") if humanoid then local target = game.Players:GetPlayerFromCharacter(humanoid.Parent) if not teamDamageEnabled and (target and target.TeamColor~=player.TeamColor) or target.TeamColor == BrickColor.new("Royal purple") or target.TeamColor == BrickColor.new("Dark stone grey") or teamDamageEnabled then if not humanoid:findFirstChild("creator") then local killTag = creatorTag:clone() killTag.Parent = humanoid debris:AddItem(killTag, 0.5) end if serverDmg then server.Hit:FireServer(humanoid, damage) else humanoid:TakeDamage(damage) end hitSound:Play() end end end tool.Name = "["..ammo.."]" end local function keyPressed(mouse,key) if not reloading and key=='r' and ammo~=clipSize then handle.Reload:Play() mouse.Icon = cursorReload tool.Name = "[REL]" reloading = true wait(reloadTime) ammo = clipSize mouse.Icon = cursorNormal tool.Name = "["..ammo.."]" reloading = false end end local function mouseClicked(mouse) mouseDown = true if not firing then while mouseDown and not reloading and ammo>0 do firing, ammo = true, ammo - 1 fire(mouse.hit.p, mouse) handle.Fire.Pitch = 1 + math.random(-20,20)/100 handle.Fire:Play() wait(fireRate) end firing = false end if ammo<=0 then keyPressed(mouse, 'r') end end tool.Equipped:connect(function(mouse) if player.Character.Humanoid.Health<=0 then return end deathCon = player.Character.Humanoid.Changed:connect(function(property) if property=="Health" and player.Character.Humanoid.Health<=0 then tool:remove() end end) mouse.Button1Down:connect(function() mouseClicked(mouse) end) mouse.Button1Up:connect(function() mouseDown = false end) mouse.KeyDown:connect(function(key) keyPressed(mouse, key) end) tool.Name = reloading and "[REL]" or "["..ammo.."]" mouse.Icon = cursorNormal hitSound.Parent = player.PlayerGui equipped=true end) tool.Unequipped:connect(function() mouseDown = false deathCon:disconnect() hitSound.Parent = nil equipped = false end) tool.Equipped:connect(function() wait() body.Torso = tool.Parent:findFirstChild("Torso") body.LeftArm, body.RightArm, body.LeftShoulder, body.RightShoulder = tool.Parent:findFirstChild("Left Arm"), tool.Parent:findFirstChild("Right Arm"), body.Torso:findFirstChild("Left Shoulder"), body.Torso:findFirstChild("Right Shoulder") if body.LeftArm and body.RightArm and body.Torso and body.LeftShoulder and body.RightShoulder then body.LeftShoulder.Part1 = nil body.RightShoulder.Part1 = nil leftWeld.Part0 = body.Torso leftWeld.Parent = body.Torso leftWeld.Part1 = body.LeftArm leftWeld.C1 = cframe(0.8,0.5,0.4)* CFrame.Angles(math.rad(270),math.rad(40),0) rightWeld.Part0 = body.Torso rightWeld.Parent = body.Torso rightWeld.Part1 = body.RightArm rightWeld.C1 = cframe(-1.2,0.5,0.4)* CFrame.Angles(math.rad(270),math.rad(-5),0) end end) tool.Unequipped:connect(function() if body.LeftArm and body.RightArm and body.Torso and body.LeftShoulder and body.RightShoulder then body.LeftShoulder.Part1 = body.LeftArm body.RightShoulder.Part1 = body.RightArm leftWeld.Parent = nil rightWeld.Parent = nil end end) repeat wait() until player.Character if server and not player.Character:findFirstChild("InfoBox") then local infoBox = instance("TextLabel", player.Character) infoBox.Name = "InfoBox" infoBox.Size = UDim2.new(0,100,0,30) infoBox.Position = UDim2.new(1,-100,1,0) infoBox.BackgroundColor3 = Color3.new(0,0,0) infoBox.BackgroundTransparency = 1 infoBox.BorderSizePixel = 0 infoBox.Font = "Arial" infoBox.FontSize = "Size24" infoBox.TextColor = BrickColor.new("White") infoBox.TextStrokeColor3 = Color3.new(0,0,0) infoBox.TextStrokeTransparency = 0 local screenGui, inProgress = instance("ScreenGui", player.PlayerGui), false local pingEvent = Instance.new("RemoteEvent", screenGui) pingEvent.Name = "Ping" pingEvent.OnClientEvent:connect(function(stamp) spawn(function() local ping = math.ceil((time() - wait() + 0.01 - stamp) * 1000) infoBox.Position = UDim2.new(1,-100,1,0) infoBox.Parent = screenGui infoBox:TweenPosition(UDim2.new(1,-100,1,-30), "Out", "Quad", 0.5, true) infoBox.TextColor3 = ping < 200 and Color3.new(0,1,0) or ping <300 and Color3.new(1, 85/255,0) or Color3.new(1,0,0) infoBox.Text = "~ "..ping.." ms" end) end) player.Chatted:connect(function(message) if string.lower(message) == "ping" and not inProgress then inProgress = true for i=1,3 do server.Ping:FireServer(pingEvent, time()) wait(2.05) infoBox.Parent = nil end inProgress = false end end) end