This is the main code for my mouse targeting system.
effects.GetCursor = function(plr, radius)
local mousePos = game.ReplicatedStorage.MiscRemoteEvents.getCursor:InvokeClient(plr)
local part = Instance.new("Part", game.Workspace)
part.Position = mousePos
part.Anchored = true
part.CanCollide = false
-- If we were given a radius, do some trig and vector math
if radius then
-- Find maximum distance in the direction of the mouse
local aimVector = mousePos - plr.Character.HumanoidRootPart.Position
aimVector = aimVector.Unit
aimVector *= radius
-- If the mouse was aimed further, return this position instead
if aimVector.Magnitude < mousePos.Magnitude then
print("too far")
return plr.Character.HumanoidRootPart.Position + aimVector
end
end
return mousePos
end
All the remote event does is return player:GetMouse().Position.
It works. I’ve used it on a separate move, and it works.
However, when I use it on this move in particular, it works sometimes, but other times…
You can see that the part is created at my mouse. The code is supposed to create the explosion the farthest it can from the player (the given radius parameter) in that direction. Clearly, as we can see from where the part is placed, the target is not out of range.
Why is it doing this? How do I fix it?