Crosshair Equip

I want to make it so when I equip the tool the crosshair shows up, but when I unequip, it goes away

image

I’ve been researching with the api but I don’t understand how to fix it.

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local mouse = Players.LocalPlayer:GetMouse()
mouse.Icon = "rbxassetid://316279304"
while true do
Tool.Equipped:Connect(function(mouse)
	UserInputService.MouseIconEnabled = true
		
		
Tool.Unequipped:Connect(function(mouse)
			UserInputService.MouseIconEnabled = false
		end)
		end

Where are you defining

Tool

I dont see a variable

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local mouse = Players.LocalPlayer:GetMouse()
local Tool = script.Parent
mouse.Icon = "rbxassetid://316279304"
while true do
Tool.Equipped:Connect(function(mouse)
	UserInputService.MouseIconEnabled = true
		
		
Tool.Unequipped:Connect(function(mouse)
			UserInputService.MouseIconEnabled = false
		end)
		end

my bad

1 Like

Hi, this error is because you didn’t close one of your parenthesis, and also you are missing an end. I have done that and re-formatted your code below:

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local mouse = Players.LocalPlayer:GetMouse()
mouse.Icon = "rbxassetid://316279304"

while true do
    Tool.Equipped:Connect(function(mouse)
        UserInputService.MouseIconEnabled = true
    end)

    Tool.Unequipped:Connect(function(mouse)
		UserInputService.MouseIconEnabled = false
	end)
end

2 Likes

I dont think you need to make

mouse

An argument. Just keep it is a Variable.

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local mouse = Players.LocalPlayer:GetMouse()
mouse.Icon = "rbxassetid://316279304"

Tool.Equipped:Connect(function(mouse)
	UserInputService.MouseIconEnabled = true
end)
		
		
Tool.Unequipped:Connect(function(mouse)
			UserInputService.MouseIconEnabled = false
		end)

You don’t need while loop.

Wait but now when I unequip it there’s no default mouse icon

Because you disabled the mouse icon.

To get the default icon put a blank string for the icon.

It should look like this:

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local mouse = Players.LocalPlayer:GetMouse()


Tool.Equipped:Connect(function(mouse)
	mouse.Icon = "rbxassetid://316279304"
end)


Tool.Unequipped:Connect(function(mouse)
	mouse.Icon = ""
end)

Hope it works!

1 Like