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

The Ball (Handle) goes in the direction of the Mouse in Studio, but not ingame. How do i fix it?

Asked by 5 years ago

To make it work, requires two Scripts, one is a normal Script and the other is a LocalScript.

LocalScript:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()


Mouse.KeyUp:Connect(function(Tecla)
    if Tecla == "e" then
        workspace.RemoteEvents.Arremessar:FireServer()
    end
end)

Script:

function Animation(v)
    Anim:Play()
    BolaHandle.Quicando.Disabled = true
    BolaTool.GripPos = Vector3.new(0, 0, 0.7)
    wait(1.5)
    BolaTool.Parent = workspace
    wait()
    BolaHandle.Quicando.Disabled = false

    local SP = Character.PrimaryPart.Position

    SP = SP + (v * 5)
    BolaHandle.Position = SP

    local Velocidade = Instance.new("BodyVelocity")

    Velocidade.MaxForce = Vector3.new(10000, 10000, 10000)
    Velocidade.P = 10000
    Velocidade.Velocity = (v * Forca.Value) + Vector3.new(0, 50, 0)
    Velocidade.Parent = BolaHandle
    wait(0.1)
    Velocidade:Destroy()
end

function Arremessar(Player)

    -- Variáveis

    repeat wait() until Player.Character
    repeat wait() until Player.Character.Humanoid


    BolaTool = Player.Character:FindFirstChild("RBB Ball")
    BolaHandle = BolaTool:WaitForChild("Handle")
    Forca = BolaTool.Arremessando.Forca

    Character = Player.Character
    local Humanoid = Player.Character:FindFirstChild("Humanoid")

    Anim = Humanoid:LoadAnimation(BolaTool.Arremessando.Arremessando)

    -- Código

    if Humanoid == nil then
        error("Humanoid não encontrado")
        return
    end

    local TP = Humanoid.TargetPoint
    local LA = (TP - Character.Head.Position).unit
    Animation(LA)
end

script.Parent.OnServerEvent:Connect(Arremessar)

The "v" in the function "Animation" doesn't work in the calcules ('SP = SP + (v * 5)' per example). The Script's objective is:

The Ball tries to go in the direction of the Mouse, but it will fall during the way.

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Olá.

Os eventos KeyDown e KeyUp estão obsoletos, não os use em novos trabalhos. Use UserInputService ou ContextActionService.

Mas o problema no seu código é que você erroneamente assume que a variável SP é uma referência à propriedade real do PrimaryPart. Se a posição do PrimaryPart mudar, as variáveis que você definiu não serão atualizadas; somente sua propriedade Position mudará. Para corrigir isso, você pode remover a variável SP e só fazer acessos diretos à propriedade Position da PrimaryPart. Você também pode modificar as variáveis para manter o próprio objeto PrimaryPart. Portanto, se a posição atual fosse Vector3.new (82, 62, 90), a linha 10 do script seria a mesma que:

local SP = Vector3.new(82, 62, 90)

Isso é um vetor sozinho, não tem nada a ver com o vetor PrimaryPart.

Ad

Answer this question