So im trying to figure out how to make this sphere go towards the ground of where my mouse position is, but it seems a little inaccurate. Any solutions? Would tweenservice work better for handling this type of stuff?
Server script
local remoteEvent = replicatedStorage:WaitForChild("RemoteEvent")
local ball = replicatedStorage:WaitForChild("Part")
local runService = game:GetService("RunService")
remoteEvent.OnServerEvent:Connect(function(player, mouseHit)
local hrm = player.Character.HumanoidRootPart
local cloneOfBall = ball:Clone()
cloneOfBall.CFrame = hrm.CFrame
cloneOfBall.Parent = workspace
cloneOfBall.Name = "Ball"
cloneOfBall.CanCollide = false
cloneOfBall.Anchored = true
runService.Heartbeat:Connect(function(dt)
cloneOfBall.CFrame = CFrame.new(cloneOfBall.Position) + mouseHit.LookVector*2
end)
end)
local UIS = game:GetService("UserInputService")
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedStorage:WaitForChild("RemoteEvent")
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
remoteEvent:FireServer(mouse.Hit)
end
end)
mouse.Origin will work with your current script instead of mouse.Hit. using mouse.UnitRay will make you have to change LookVector with Direction on the Server Script
After thinking about it, you could make a tween using TweenService that tweens the sphere position to the mouse.hit.p and the time it takes be the difference between the sphere position and mouse.hit.p.