I am trying to make a gun that fits all my criteria and it was going well until now. I made a code that every time a player clicks the mouse, It notes the barrel position which is an extra secret part which just is a place to spawn the bullet. Unfortunately, I have to use a local script because the server script will spawn the bullet at the hidden gun where you were working on it. So, I wanted to use a remote event to send info to the server script to spawn the bullet there. But for some reason it says 'VoltyDeElectroDragon 328.80020141602 3.400004863739' instead of '328.80020141602 3.400004863739 -144.67500305176' and I don't know whats wrong. The same problem occured in a different version of my gun. Here's the local script code:
local mouse = player:GetMouse()
local barrel = script.Parent:WaitForChild("Barrel", 0.00001)
local barrelx = barrel.Position.X
local barrely = barrel.Position.Y
local barrelz = barrel.Position.Z
script.Parent.Equipped:Connect(function()
script.Parent.Activated:Connect(function()
local HitX = mouse.Hit.X
local HitY = mouse.Hit.Y
local HitZ = mouse.Hit.Z
print(barrelx, barrely, barrelz)
script.Parent.Fire:FireServer(barrelx, barrely, barrelz)
end)
end)
And here is the Server Script code:
local bullet = game.ReplicatedStorage.Bullet
local gunposX = script.Parent.Barrel.Position.X
local gunposY = script.Parent.Barrel.Position.Y
local gunposZ = script.Parent.Barrel.Position.Z
local function Fire(barrelx, barrely, barrelz)
print(barrelx, barrely, barrelz)
part.Position = Vector3.new(HitX, HitY, HitZ)
local bulletcopy = bullet:Clone()
bulletcopy.Parent = game.Workspace
bulletcopy.Position = Vector3.new(gunposX, gunposY, gunposZ)
local Bulletshoot = Instance.new("BodyForce", bulletcopy)
Bulletshoot.Force = Vector3.new(0, 0, 100)
end
script.Parent.Fire.OnServerEvent:Connect(Fire)