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 5 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):

01script.Parent.Events.RequestBulletLocation.OnServerEvent:Connect(function(player, BulletLocation, End)
02            script.Parent.Values.BulletLocation.Value = BulletLocation
03            script.Parent.Values.BulletEnd.Value = End
04            positionSet = true
05        end)
06 
07        repeat wait(.00001) until positionSet == true
08 
09        positionSet = false
10 
11        local ray = Ray.new(script.Parent.Values.BulletLocation.Value, root.CFrame.lookVector*500)
12        print(ray.Direction)

LOCALSCRIPT IN STARTERPACK:

1local function fetchBulletLocation()
2    game.Players.LocalPlayer.Character:FindFirstChildOfClass("Tool").Events.RequestBulletLocation:FireServer(weapon.BulletLocation.Position, weapon.BulletLocation.CFrame.lookVector*500)
3end
4 
5game.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:

1-495.047577, 52.0999603, -47.0481949
2 -496.878479, -0.473964512, -55.7814674
3 -496.806519, -0, -56.420723
4 -496.444763, -0, -59.5198288 (x2)
5 -497.378632, -0, -51.1327477
6 -497.480469, -0, -50.1319847
7 -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 — 5y

Answer this question