Mouse icon "Cross" is not showing in game

I’m experiencing an issue with the mouse icon “Cross”—it’s not displaying in the game. :frowning:

whats wrong? :pray:

localscript:

-- Get references to the local player and mouse
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

-- Get a reference to the server-side event
local fireEvent = script.Parent.gunFire

-- Connect the script to the Equipped event
script.Parent.Equipped:Connect(function()
	local uis = game:GetService("UserInputService")
	mouse.Icon = "rbxasset://SystemCursors/Cross"
	-- uis.MouseIcon = "rbxasset://SystemCursors/Cross"
	uis.MouseIconEnabled = true
end)

-- Connect the script to the Activated event
script.Parent.Activated:Connect(function()
	-- Get the target under the mouse
	local target = mouse.Target
	if target and target.Parent then
		-- Fire the server event with the parent of the target
		fireEvent:FireServer(target.Parent)
	end
end)

2 Likes

Since you’re in first person, I recommend simply disabling the default mouse cursor, and placing a UI element in the center of the screen. This will please mobile users, and console users as well.

1 Like

Oh, I hadn’t thought about that! Thank you very much, I’ll do that!

By the way… Is this the right way to create a weapon system with “Activated,” or should I use raycasting?

If you’re making an advanced system, and your an advanced scripter, then you wouldn’t use Tools for guns. But if you’re not there yet, then this is probably fine. But, to step it up, you can avoid using Activated and only listen to mouse clicks while the tool is equipped.

1 Like

Thanks you alot!

One last question… I tried placing an ImageLabel at the center of the screen, but it’s not working properly. It should hide when not equipped and show when equipped. What could be wrong?

-- Get references to the local player and mouse
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

-- Get a reference to the server-side event
local fireEvent = script.Parent.gunFire

local mouseIcon = game.StarterGui:WaitForChild("MouseIcon-Center").ImageLabel.Visible

-- Connect the script to the Equipped event
script.Parent.Equipped:Connect(function()
	-- Make the ImageLabel visible
	mouseIcon = true
end)

-- Connect the script to the Unequipped event
script.Parent.Unequipped:Connect(function()
	-- Make the ImageLabel invisible
	mouseIcon = false
end)

-- Connect the script to the Activated event
script.Parent.Activated:Connect(function()
	-- Get the target under the mouse
	local target = mouse.Target
	if target and target.Parent then
		-- Fire the server event with the parent of the target
		fireEvent:FireServer(target.Parent)
	end
end)

I was able to solve it! :smiley:

-- Get references to the local player and mouse
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

-- Get a reference to the server-side event
local fireEvent = script.Parent.gunFire

local playerGui = player.PlayerGui
local playerGUI = playerGui:WaitForChild("MouseIcon-Center") 

-- Connect the script to the Equipped event
script.Parent.Equipped:Connect(function()
	-- Make the ImageLabel visible
	playerGUI.Enabled = true
end)

-- Connect the script to the Unequipped event
script.Parent.Unequipped:Connect(function()
	-- Make the ImageLabel invisible
	playerGUI.Enabled = false
end)

-- Connect the script to the Activated event
script.Parent.Activated:Connect(function()
	-- Get the target under the mouse
	local target = mouse.Target
	if target and target.Parent then
		-- Fire the server event with the parent of the target
		fireEvent:FireServer(target.Parent)
	end
end)

Setting a variable to another works, but it doesn’t remember where it came from.

local apple = 1
local orange = apple
print(apple, orange) --> 1, 1
apple = 2
print(apple, orange) --> 2, 1

In your case, you can’t set an instance property by changing a variable.

local visible = player.PlayerGui.ScreenGui.Frame.Visible
visible = false
-- Visiblity has not changed, only the variable has

To fix the problem, just make a variable for the frame.

local frame = player.PlayerGui.ScreenGui.Frame
frame.Visible = false
-- Visibility has changed
Why do instance variables remember?

Behind the scenes, instances are just tables. Tables are special because they are remembered differently.

local data = {Name = "blueberry"}
print(data.Name) --> blueberry
data.Name = "avocado"
print(data.Name) --> avocado
-- normal variables:
local a = 1
local b = a
print(a, b) --> 1, 1
a = 3
print(a, b) --> 3, 1 

-- table variables:
local a = {1}
local b = a
print(a, b) --> {1}, {1}
a[1] = 3
print(a, b) --> {3}, {3}

Well, why? Tables are remembered using memory addresses. It’s a location to look in to find the variable. Setting a variable to a table just tell it it’s memory address. That means, two variables will point to the same thing, even if something changes it.

1 Like

Oh, thank you so much, this has really helped me a lot, thank you! By the way, I sent you a private message, but I’m not sure if it was sent correctly. Could you please let me know?

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.