I made a viewmodel gun, i have it setup to where its parented to the workspace.
this is the local script that sends over the starting position and destination for the bullet
local plyr = game.Players.LocalPlayer
local repstorage = game.ReplicatedStorage
local rs = game:GetService("RunService")
local cam = workspace.CurrentCamera
local m = plyr:GetMouse()
local char = plyr.Character
local viewmodel = repstorage.ViewModel:Clone()
local gun = viewmodel.Gun
viewmodel.Parent = workspace
rs.RenderStepped:Connect(function()
viewmodel.Head.CFrame = cam.CFrame
end)
m.Button1Down:Connect(function()
repstorage.Events.fire:FireServer(gun.Hole.Position,m.Hit.Position,plyr)
end)
this script below is the server side which creates the bullet and sets its position and cframe
local repstorage = game.ReplicatedStorage
repstorage.Events.fire.OnServerEvent:Connect(function(plyr,start,destination)
local dist = (destination-start).Magnitude
local bullet = Instance.new("Part")
bullet.Parent = workspace
bullet.CanCollide = false
bullet.Anchored = true
bullet.CFrame = CFrame.new(start,destination)*CFrame.new(0,0,-dist/2)
bullet.Size = Vector3.new(0.1,0.1,dist)
end)
this video shows my problem, basically whenever the bullet is created, it ends up somewhere random, or directly below me as shown in the video, and I have completely no idea why its happening! i also switched around the destination and start variables to show that those are not the problem. Does anyone know what is causing this or why its happening?
