Why can't I change the length of a ray?

If they delete it on their client, the touched event does not fire. I’m not saying they have access to the server scripts, I’m saying the touched event internally relies on clients to tell it when it has fired and exploiters can manipulate it.

I see. Thanks for letting me know. But truthfully if they delete that script in the client then it will only go against them because when their weapon fires it won’t deal any damage to anyone and you can’t do vice versa because the server script handles damage. So I think i’m fine with that (or at least I think so). Thanks.

It seems that the issue is with how you are visualizing the ray. The Raycast method returns a RaycastResult object which contains information about the hit point and distance of the raycast. The length of the ray itself is not changed by setting the direction or distance of the raycast.

To visualize the ray, you can create a Part object and set its Size property to the Vector3 value of the distance between the ray’s origin and hit point, and its CFrame property to the CFrame value of the hit point. Here’s an example of how you can do this:

vbnetCopy code

local ray = workspace:Raycast(gun.Position, gun.CFrame.LookVector * 500)
if ray then
    local part = Instance.new("Part")
    part.Anchored = true
    part.CanCollide = false
    part.Transparency = 0.5
    part.Size = Vector3.new(0.1, 0.1, ray.Distance)
    part.CFrame = CFrame.new(gun.Position, ray.Position) * CFrame.new(0, 0, -ray.Distance/2)
    part.Parent = workspace
end

This will create a semi-transparent Part object that represents the ray, with its length set to the distance between the gun and the hit point.

oh boy another chatgpt response, you didnt even remove the “copy code” button!

3 Likes

Off topic but:

ChatGPT is really becoming the norm now days, I’m telling you: Solution Addicts

1 Like

when you’re testing the raycast, are you making sure there is a part in front of you for the ray to hit?

if the ray doesn’t hit anything, it won’t return a distance, so you have to manually set the default length of the part to the max distance of the raycast.