I am currently using the Raycast Hitbox module to detect when a player runs through a part, due to inconsistencies with .Touched events at high speeds I saw this as the best option.
However for some reason the rays sometimes don’t register this hit as you can see in the video below:
I have looked for some solutions to this but have not yet come across one, anyone got some suggestions on how I could improve this reliability (and will be effective with very high player velocities), or if there is a better way of going about this?
Script I am using to do this
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RaycastHitbox = require(ReplicatedStorage.RaycastHitboxV4)
local Players = game:GetService("Players")
local events = ReplicatedStorage:WaitForChild("events")
local gatePassed = events:WaitForChild("gatePassed")
local hitbox = script.Parent
local character = hitbox.Parent
if hitbox:FindFirstAncestorOfClass("Model") == character then
player = Players:GetPlayerFromCharacter(character)
end
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {hitbox,character}
Params.FilterType = Enum.RaycastFilterType.Blacklist
local newHitbox = RaycastHitbox.new(script.Parent)
newHitbox.RaycastParams = Params
newHitbox.Visualizer = false
newHitbox.DetectionMode = 2
newHitbox:HitStart()
local leaderstats = player:FindFirstChild("leaderstats")
local coins = leaderstats:FindFirstChild("Coins")
local data = player:FindFirstChild("Data")
local XP = data:FindFirstChild("XP")
local rebirths = leaderstats:WaitForChild("Rebirths")
local moreXP = data:WaitForChild("moreXPUpgrade")
local values = player:WaitForChild("Values")
local trailMultiplier = values:WaitForChild("trailMultiplier")
newHitbox.OnHit:Connect(function(hit)
print("hit")
if hit.Name == "winGate" then
local gateNumber = tonumber(hit.SurfaceGui.TextLabel.Text)
if gateNumber == 500 then
character.HumanoidRootPart.Velocity = Vector3.new(0, 0, 0)
end
if gateNumber < 16 then
coins.Value = coins.Value + (1+(rebirths.Value*2))
XP.Value = XP.Value + ((25+((moreXP.Value+1)*2))*trailMultiplier.Value)
elseif gateNumber >= 16 and gateNumber < 46 then
coins.Value = coins.Value + (3+(rebirths.Value*2))
XP.Value = XP.Value + ((35+((moreXP.Value+1)*2))*trailMultiplier.Value)
elseif gateNumber >= 46 and gateNumber < 106 then
coins.Value = coins.Value + (5+(rebirths.Value*2))
XP.Value = XP.Value + ((50+((moreXP.Value+1)*2))*trailMultiplier.Value)
elseif gateNumber >= 106 and gateNumber < 226 then
coins.Value = coins.Value + (10+(rebirths.Value*2))
XP.Value = XP.Value + ((75+((moreXP.Value+1)*2))*trailMultiplier.Value)
elseif gateNumber >= 226 then
coins.Value = coins.Value + (15+(rebirths.Value*2))
XP.Value = XP.Value + ((100+((moreXP.Value+1)*2))*trailMultiplier.Value)
end
gatePassed:FireClient(player)
end
end)
Not too well versed in the Raycast Hitbox module but it may be because youre detecting it on the server. (an educated guess) usually you would want to have a server detect if they are near or touching something then firing a remote event and then the server can check if they are near enough to actually be touching (if you are worrying about an exploiter cheating with this they can already modify their movespeed).
or you could just have it track the root part positions every .1 seconds or something and raycast between the points but the Raycast Hitbox module may do this already from what I skimmed off the page
Thanks, I’ve just switched it to a local script, I forgot they could run in the character.
However I don’t think that is the issue, from the local script out of 500 gates passed 491 registered at a speed of 10k. I then tested it again with a server script at the same speed, that time 495 registered.
I understand some may be missed at high speeds, but I’m not sure why its sometimes missing them at low speeds like the video.
It wont be, I have it from slightly behind the player and I have my player running in a straight line. I just tried with no blacklist and came out with 469/500, I don’t think the parameters are the performance hinderance.
maybe the detectionmode has a different value that works better or maybe theres a delay between stuff cause i havent had an issue with raycasts even when firing 100s a second. maybe you wanna use your own detection thing but thats prob a last resort
That’s the detection mode that would work for me in this case, I think I might look about changing round the hitbox and where the attachments are, I currently have 3 horizontally placed ones spanning the width 3.5 studs, idk if that might be the cause.
problem with that is if you are moving too fast you could skip a frame where you were on that part so it is better to use a raycast and check between positions so you dont miss anything
If you think about it, Magnitude is technically a raycast since it calculates the distance between certain objects and if its a certain distance, it can do certain things, similar to raycast.
That’s not true. When CanCollide is set to true, CanQuery is always enabled. As you can tell from the video, the player is going through the wall, meaning CanCollide is more than most likely set to false.
Your point is? Just because it starts off enabled for brand new parts, that doesn’t mean it’s not possible for it to be turned off. All it takes is one accidental click (or one copy and paste of a part that has it set to false) to have yourself a part that has CanQuery set to false.
Its always Enabled and i doubt anybody would disable it for any Reason, Usually only CanTouch and CanCollide
What is your point in arguing? I just want to help like anyone else?
I dont think it really matters, plus dont argue in a Public post, just a DM, if it works it works, im just expressing my idea’s, if i disagree, i’ll explain why i disagree and not Start an argument because of it, nothing more