My problem is this
I’m trying to accurately position an object when the position is moving for example, https://streamable.com/o2kn9u and https://streamable.com/9ls5w2.
This is my code
—LocalScript
local Physics_Run = game:GetService("RunService")
local User_Input = game:GetService("UserInputService")
local User = game.Players.LocalPlayer
local Mouse = User:GetMouse()
local Remotes = script:WaitForChild("Remotes")
local Gun = script.Parent
local Ammo = Gun.Configuration.Ammo
local Max_Ammo = Gun.Configuration.MaxAmmo
local Auto = false
local AutoSpeed = .05
local Click_Began
local Click_Ended
Gun.Equipped:Connect(function()
Click_Began = User_Input.InputBegan:Connect(function(Input,GPE)
Auto = true
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
repeat
Remotes.Shoot:FireServer(Mouse.Hit.Position)
wait(AutoSpeed)
until not Auto
end
end)
Click_Ended = User_Input.InputEnded:Connect(function(Input,GPE)
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
Auto = false
end
end)
end)
Gun.Unequipped:Connect(function()
Click_Began:Disconnect()
Click_Ended:Disconnect()
end)
—ServerScript
local Gun = script.Parent.Parent
local Ammo = Gun.Configuration.Ammo
local MaxAmmo = Gun.Configuration.MaxAmmo
local Remotes = script.Parent.Remotes
Remotes.Shoot.OnServerEvent:Connect(function(User,Mouse_Location)
local RayFilter = RaycastParams.new()
RayFilter.FilterDescendantsInstances = {User.Character}
RayFilter.FilterType = Enum.RaycastFilterType.Blacklist
local RayCast = workspace:Raycast(Gun.BulletOffset.Position,(Mouse_Location - Gun.BulletOffset.Position).Unit * 100,RayFilter)
if RayCast then
local RayPart = Instance.new("Part")
RayPart.Anchored = true
RayPart.CanCollide = false
RayPart.Size = Vector3.new(.3,.3,(Gun.BulletOffset.Position - RayCast.Position).Magnitude)
RayPart.CFrame = CFrame.lookAt((Gun.BulletOffset.Position + RayCast.Position)/2,RayCast.Position)
RayPart.Parent = User.Character
game.Debris:AddItem(RayPart,.3)
end
Ammo.Value = math.clamp(Ammo.Value - 1,0,MaxAmmo.Value)
end)
How would i achieve this?