Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is my Gun Returning it's Ray's Direction as not straight only sometimes?

Asked by 4 years ago

Hey guys!

So basically, I'm trying to make a First Person Shooter, and my guns use this system when firing:

1) Call the Client and ask them where their viewModel is 2) Client calls back with the information needed 3) Use that information to create a Ray.

Here's my code:

SCRIPT IN GUN (REAL ONE):

script.Parent.Events.RequestBulletLocation.OnServerEvent:Connect(function(player, BulletLocation, End)
            script.Parent.Values.BulletLocation.Value = BulletLocation
            script.Parent.Values.BulletEnd.Value = End
            positionSet = true
        end)

        repeat wait(.00001) until positionSet == true

        positionSet = false

        local ray = Ray.new(script.Parent.Values.BulletLocation.Value, root.CFrame.lookVector*500)
        print(ray.Direction)

LOCALSCRIPT IN STARTERPACK:

local function fetchBulletLocation()
    game.Players.LocalPlayer.Character:FindFirstChildOfClass("Tool").Events.RequestBulletLocation:FireServer(weapon.BulletLocation.Position, weapon.BulletLocation.CFrame.lookVector*500)
end

game.Players.LocalPlayer.Character:FindFirstChildOfClass("Tool").Events.RequestBulletLocation.OnClientEvent:Connect(fetchBulletLocation)

Now, the issue is that when it prints the direction, it printed 1 time with a Y axis that wasn't 0 out of 26 (counted in the most recent 26 shots).

Here's an example of the output:

 -495.047577, 52.0999603, -47.0481949
  -496.878479, -0.473964512, -55.7814674
  -496.806519, -0, -56.420723
  -496.444763, -0, -59.5198288 (x2)
  -497.378632, -0, -51.1327477
  -497.480469, -0, -50.1319847
  -498.216125, -0, -42.1985779

I hope you can help me! Thanks for reading!

0
I know this is not really helping you but maybe you can use Mouse.Hit(this will return the CFrame of the pointer's CFrame) as a BulletEnd CFrame value. https://developer.roblox.com/api-reference/property/Mouse/Hit Block_manvn 395 — 4y

Answer this question