[v1.5] Create Dynamic Crosshairs! (Updated!)

When I saw this had been updated twice, I did a little happy dance in my head, especially when I noticed easing styles were added. However, when I implemented the new module, I got this error on line 197:

path.DynamicCrosshair:197: attempt to index nil with 'spread'`

It’s coming from the :SmoothSet() function in the module. I made 100% sure by removing :SmoothSet() from my code, and it didn’t return an error.

I am using this code from the v1.1 post.

How can I fix this? Am I doing something wrong?

Thanks,
Fizzitix

2 Likes

You can try to accomplish this by possibly using DynamicCrosshair’s :Display() function? Seems like kind of a stretch so maybe a built-in function that does this exact thing can be seen in a future update.

Stay tuned for upcoming update releases!

I’ll give it a look thanks for the reply.

That documentation is outdated to my knowledge, which is at the top of my to-do list to update.
Maybe create a separate website for documentation? If it’s a good idea ~

I’ll reply as soon as I can with a fix or patch for the module!

2 Likes

Just ran the code and replicated the same error:
image

After looking into it I found out it was a capitalization problem :sweat_smile:
Silly error that should’ve been fixed a while ago

Module is update!
Download here: DynamicCrosshair - Roblox

2 Likes

Thanks so much! This module is super, super useful. Keep it up!

Fizzitix

2 Likes

Update v1.3 (Documentation Update!) :white_check_mark:

Finally, FINALLY! New DynamicCrosshair documentation hosted by GitHun Pages!

Go check it out here: Documentation

If you find any issues or problems with the website shoot me a message on discord or the devforum!
Discord: Towphy#6174

Module Updates

Update v1.3 doesn’t just include new documentation, but a few new module updates!

Hitmakers

You can now customize the hitmakers default and headshot image!
Example here:

local UI : ScreenGui = script.Parent 
local DynamicCrosshair = require(script.DynamicCrosshair).New(UI)
DynamicCrosshair:Enable()

DynamicCrosshair.HitMarker.Image.default  = "rbxassetid://285779644"
DynamicCrosshair.HitMarker.Image.headshot = "rbxassetid://285779644"
DynamicCrosshair:Hitmarker(true)

If the HitMarker.Image.headshot is left nil, it will default to HitMarker.Image.default

Very minor changes to the following functions:

DynamicCrosshair:Set()
DynamicCrosshair:Lock()
DynamicCrosshair:Hitmarker()

Download The Module Here:

As always, if you run into any problems with the website or module respond to this post or reach out to me on my socials (located on the documentation website) :slight_smile:

4 Likes

Hello, I am currently experiencing a problem related to :Raycast().

I’m not sure if it’s my coding or the module itself, but the direction it returns is inaccurate. I made sure of blacklisting character itself from the raycast, and followed the documentation well, but unfortunately, the problem still persists.

If needed, here is how my code looks like.

function FireProjectile()
	local VIEWPORT_SIZE = Camera.ViewportSize
	local CAST_LENGTH = Tool:GetAttribute("BulletMaxDist")
	
	raycastParams.FilterDescendantsInstances = {Character, IgnoreList}
	
	local _, direction = DynamicCrosshair:Raycast()
	local unitRay = Camera:ScreenPointToRay(VIEWPORT_SIZE.X / 2, VIEWPORT_SIZE.Y / 2 - game:GetService("GuiService"):GetGuiInset().Y)
	local raycastResult = workspace:Raycast(unitRay.Origin, direction * CAST_LENGTH, raycastParams)

	local TargetPosition = if raycastResult then raycastResult.Position else unitRay.Origin + direction * CAST_LENGTH
	
	if not isInSafeMode then
		MouseEvent:FireServer(TargetPosition)
	end
	
	if RoxiteSettings.Debug then
		local Line, Cone = Gizmo:DrawArrow(unitRay.Origin, TargetPosition, Color3.fromRGB(85, 186, 255))
		game:GetService("Debris"):AddItem(Line, 5)
		game:GetService("Debris"):AddItem(Cone, 5)
	end
end

If it’s just my scripting, please correct me.

Hmm, interesting, it could possibly be because of the Camera:ScreenPointToRay you use in your code, since DynamicCrosshair already does that for you, but I doubt it.
I’d say try it without it and see if anything changes.

try this
function FireProjectile()
	local CAST_LENGTH = Tool:GetAttribute("BulletMaxDist")
	
	raycastParams.FilterDescendantsInstances = {Character, IgnoreList}
	
	local origin, direction = DynamicCrosshair:Raycast()
	local raycastResult = workspace:Raycast(origin, direction * CAST_LENGTH, raycastParams)

	local TargetPosition = if raycastResult then raycastResult.Position else origin + direction * CAST_LENGTH
	
	if not isInSafeMode then
		MouseEvent:FireServer(TargetPosition)
	end
	
	if RoxiteSettings.Debug then
		local Line, Cone = Gizmo:DrawArrow(origin, TargetPosition, Color3.fromRGB(85, 186, 255))
		game:GetService("Debris"):AddItem(Line, 5)
		game:GetService("Debris"):AddItem(Cone, 5)
	end
end

If the problem persists could you send a Roblox file so I can take a look myself? My socials are all on the documentation website!

The problem persists, nonetheless.

I can give you the file in your private message to troubleshoot the issue, whether it is my scripting or your module.

Hmm strage it seemed that the :set function caused some enormous leak when used in consecutive order every frame

Update v.1.4 (Center dot and image crosshairs!) :white_check_mark:

DynamicCrosshair has received a new update with 2 new previously suggested features, Center Dots and Image Crosshairs


Center Dots

Center dot is a image that always stays in the middle of the crosshair, pretty simple.

Example:

image

Example Code
local rep = game:GetService('ReplicatedStorage')
local DynamicCrosshair = require(rep:WaitForChild('DynamicCrosshair')).New(script.Parent)

local uis = game:GetService('UserInputService')
DynamicCrosshair:Enable()

DynamicCrosshair:Size(15, 3)

DynamicCrosshair:Display({
	BackgroundTransparency = 0; 
	BorderSizePixel = 0;
	Image = nil;
	ImageTransparency = 0;
	BackgroundColor3 = Color3.new(1, 1, 1);
})

DynamicCrosshair.CenterDot.enabled = true
DynamicCrosshair.CenterDot.size = UDim2.fromOffset(5,5)

Usage:

DynamicCrosshair.CenterDot.enabled = true -- default: false
DynamicCrosshair.CenterDot.size = UDim2.fromOffset(x,y) -- default: UDim2.fromOffset(7.5,7.5)
DynamicCrosshair.CenterDot.transparency = 0 -- default: 0
DynamicCrosshair.CenterDot.Image = 'rbxassetid://xxxxxxx' -- default: rbxassetid://11003529439

Image Crosshairs

Image crosshairs are pretty self-explanatory. They are single-image crosshairs that are as big as a normal crosshair would be. They work with all built-in functions.
Once the image crosshair is enabled all other crosshairs are disabled. The center dot will still exist.

Example:

image

Example Code
DynamicCrosshair.ImageCrosshair.enabled = true

Usage:

DynamicCrosshair.ImageCrosshair.enabled = true -- default: false
DynamicCrosshair.ImageCrosshair.Image = 'rbxassetid://xxxxxxx' -- default: rbxassetid://12550071496

Minor Updates:

The function :Size can take 1 argument instead of 2.
Example:

-- DynamicCrosshair size is (5, 1)
DynamicCrosshair:Size(10) -- size will result in (10,1)
DynamicCrosshair:Size(10,10) -- size will result in (10,10)

Statuses:

  • Documentation is not updated (stay tuned)
  • Module is updated

As always, if you run into any problems with the website or module respond to this post or reach out to me on my socials (located on the documentation website) :slight_smile:

1 Like

Really? seems odd, could you send some examples?

The module isn’t very… performance well. WORK IN PROGRESS THOUGH! :sweat_smile:

1 Like

finally been waiting for this lol
are there any demonstration for this??

Yup demonstrations should be available on the documentation once it’s updated. Expect it to be updated in about 1 day. I’ll @ you once it is updated!

Found this documentation bug if i’m pretty sure but smooth set enum is duplicated and incorrectly named, or was it intended to be like that?

also smooth set now doesn’t tween whenever i try to use it and uses default set, Do i need to use some functions in order to make it work or missing something here?

localscript
local rep = game:GetService('ReplicatedStorage')
local UI : ScreenGui = script.Parent 
local DynamicCrosshair = require(rep:WaitForChild('DynamicCrosshair')).New(UI, 40, 80, 30, 30)
local playerSV = game:GetService("Players")
local clientPL = playerSV.LocalPlayer
local mouse = clientPL:GetMouse()

local uis = game:GetService('UserInputService')
DynamicCrosshair:Enable()
--DynamicCrosshair:Set(40)
DynamicCrosshair:Size(30, 6)

DynamicCrosshair.ImageCrosshair.enabled = true
DynamicCrosshair.ImageCrosshair.Image = "rbxassetid://10281651490"
--DynamicCrosshair:Display({
--	BackgroundTransparency = 0; 
--	BorderSizePixel = 0;
--	Image = nil;
--	ImageTransparency = 0;
--	BackgroundColor3 = Color3.new(1, 1, 1);
--})

DynamicCrosshair.EasingStyle = Enum.EasingStyle.Bounce -- default: linear
DynamicCrosshair.EasingDirection = Enum.EasingDirection.Out -- default: InOut

-- DynamicCrosshair:SmoothSet(Spread, Transition Seconds, Update Minimum Radius When Completed)



DynamicCrosshair.CenterDot.enabled = true
DynamicCrosshair.CenterDot.size = UDim2.fromOffset(5,5)

mouse.Button1Down:Connect(function()
	DynamicCrosshair:SmoothSet(60, 0, false)
end)

What seems to be a small mistake in the documentation thanks for pointing that out :sweat_smile:

Now for your :SmoothSet(), you have the seconds parameter set to 0 meaning it won’t have the “bounce/smooth effect”. To change this just set this to seconds parameter to something to your liking such as

-- :SmoothSet(spread, seconds, updateMin)
:SmoothSet(60, 1) -- will take 1 second to "bouncingly " set

If you have any other problems or this doesn’t work for you reply to this message!

But that’s not what i expected it to do aswell, all it does for me is the delay from input (though i set the second to 1 but it still doesn’t tween)

could you shoot me a private message so we could further talk about this? Possibly with a place file and make sure the module is updated. Sorry for the inconvenience

Would you advise against using the module in that case?

I’ve actually updated the module to be more performant. I’ve used it in plenty of games and its very light-weight.

1 Like