Why is my Gun Returning it's Ray's Direction as not straight only sometimes?
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):
01 | script.Parent.Events.RequestBulletLocation.OnServerEvent:Connect( function (player, BulletLocation, End) |
02 | script.Parent.Values.BulletLocation.Value = BulletLocation |
03 | script.Parent.Values.BulletEnd.Value = End |
07 | repeat wait(. 00001 ) until positionSet = = true |
11 | local ray = Ray.new(script.Parent.Values.BulletLocation.Value, root.CFrame.lookVector* 500 ) |
LOCALSCRIPT IN STARTERPACK:
1 | local function fetchBulletLocation() |
2 | game.Players.LocalPlayer.Character:FindFirstChildOfClass( "Tool" ).Events.RequestBulletLocation:FireServer(weapon.BulletLocation.Position, weapon.BulletLocation.CFrame.lookVector* 500 ) |
5 | 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:
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 (x 2 ) |
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!