Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Throwing Objects at objects/players is not accurate?

Asked by 4 years ago
Edited 4 years ago

as the name implies, For some odd reason it doesn't work accurately.. I'm about 90% sure it's because of the Mouse.Hit

If I point the mouse at nothing, it works perfectly.

If I point the mouse at an object, It becomes inaccurate.

I've been stuck on this for about a week or so. Any help would be greatly appreciated.

LocalScript

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local RemoteEvent = game.ReplicatedStorage:WaitForChild("Remotes").ThrowingRemotes.Throwing_Event
local Tool = script.Parent.Parent
--Variable

--Activated
Tool.Activated:Connect(function()   

    RemoteEvent:FireServer(Mouse.Hit)

end)    

Script

local Remotes = game.ReplicatedStorage:WaitForChild("Remotes")
local RemoteEvent = game.ReplicatedStorage.Remotes.ThrowingRemotes.Throwing_Event
local items = game.ReplicatedStorage:WaitForChild("Kitchen").items_that_have_been_thrown.Soda

--Variables

local function MoveTowardsMouse(Mouse, item) -- Throwed item will follow the item.

    --Fling it towards the mouse.
    local BodyVelocity = Instance.new("BodyVelocity")
    BodyVelocity.MaxForce = Vector3.new(50000,50000,50000)
    BodyVelocity.Velocity = CFrame.new(item.Position, Mouse.Position).LookVector * 65 -- speed
    BodyVelocity.Parent = item

    --Makes the item spin.
    local BodyGyro = Instance.new("BodyGyro")
    BodyGyro.MaxTorque =  Vector3.new(5000,5000,0)
    BodyGyro.P = 1000 -- Power
    BodyGyro.CFrame = CFrame.new(item.Position, Mouse.Position)
    BodyGyro.Parent = item
end

RemoteEvent.OnServerEvent:Connect(function(Player, Mouse_CFrame)
    local Character = Player.Character
    local Clone = items:Clone()
    local RootPart = Character:WaitForChild("HumanoidRootPart")
    local HeldItem = Character:WaitForChild("Soda").Soda1
    --Variables

    MoveTowardsMouse(Mouse_CFrame, Clone)

    Clone.Parent = workspace
    Clone.CFrame = CFrame.new(HeldItem.Position)        
end)

https://gyazo.com/87485449a845867dbf969413421193a2

Thanks in advance.

0
always parent as last VerdommeMan 1479 — 4y
0
also try removing the bodygyro and see if that thing messes up the accuracy VerdommeMan 1479 — 4y

Answer this question