Trouble with making an aim for my game

yo im having a trouble with making aim to my firestaff.
aim need to be visible when player presses RMB. I only know it should be a GUI. I need an example of the GUI script.

1 Like

could you elaborate a little more please?

if you want to make a GUI visible when the player pressing rmb you can listen for inputs that match and detect when the user presses and unpresses right click, then you can simply make the GUI visible, or non visible

i dont need Gui as much as i need an aim which could be visible when player press and visible when player unpress . Of course with weapon in his hand.

i mean not visible when unpress

soo, pretty much a crosshair, which can be used to aim when right click is pressed?

something like that. But guess it must be a GUI.

ive made a quick example for you,
this will make a frame visible or not visible depending if the right mouse button is being held down.
if you have any questions please ask.

local aim = script.Parent -- which in my testing case is a frame
local uis = game:GetService("UserInputService") -- we'll use this service to see when the player presses right click

local function onRightClickDown(input, gameProcessedEvent)
	if input.UserInputType == Enum.UserInputType.MouseButton2 and -- if the input is the right mouse button (rmb)
		not gameProcessedEvent then -- makes sure roblox isnt using rmb for something
		print("right mouse button pressed")
		aim.Visible = true -- makes sure the gui is visible when rmb is pressed
	end
end

local function onRightClickUp(input, gameProcessedEvent)
	if input.UserInputType == Enum.UserInputType.MouseButton2 and
		not gameProcessedEvent then 
		print("right mouse button released")
		aim.Visible = false -- makes sure the gui is NOT VISIBLE when rmb is released
	end
end

-- connect the functions to the uis events
uis.InputBegan:Connect(onRightClickDown)
uis.InputEnded:Connect(onRightClickUp)

the explorer for this test looks like this.
image

can i make this through creating image label?

yes! that is also possible and will work the same just by replacing the ‘frame’ with an image label.

so the script will remain in frame as i guess

the script will dynamically detect the parent to the script, meaning you will have to move the script object in the explorer to the image label
image
as you can see I have added a new imagelabel under screengui, and I’ve moved my localscript to the imagelabel as a child.

you also do not need the frame anymore, you can remove that if needed

image label can be visible even through not be frame child?

yes, an image label can be put under the ScreenGui object, it doesn’t always have to be put under a frame but frames help keep other elements organised and can act as a background.

1 Like

Thanks. I ll ask if i ll have troubles

1 Like

can i ask one more question? This is about making player mouse lock on crosshair when RMB pressed

if thats what your aiming for, you could either make something similar to shift lock or something like making the crosshair go into the center of the screen,
a major decider would be if your game is either first person or third person, meaning the player is locked in the actual point of view of the character instead of watching over it in third person.

really thanks. Helped a lot with this thing.

1 Like

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