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

Ball throws to middle of the map?

Asked by 5 years ago

This is my second time posting this but I REALLY, want an answer.

I've tried seeing whats wrong because this works PERFECTLY FINE in studio but not in-game.

Basically, the ball throws to the middle of the map in a real game like 0,0,0 but in studio it works fine. Any ideas? Thanks

local Tool = script.Parent;
local bodyp = Instance.new("BodyPosition")
local targetPos = nil
local lookAt = nil

enabled = true

function fire(v)
    if(Tool.Handle.FlyingSound.IsPlaying == false) then
        Tool.Handle.FlyingSound:Play()
    end

    local vCharacter = Tool.Parent
    local vPlayer = game.Players:playerFromCharacter(vCharacter)
    local anim = vCharacter.Humanoid:LoadAnimation(Tool.pitchAnim)

    local missile = Tool.Handle

    local spawnPos = vCharacter.PrimaryPart.Position
    anim:Play()
    wait(1.23)

    targetPos = spawnPos + (v * Tool.Power.Value)

    Tool.Parent = game.Workspace

    bodyp.maxForce = Vector3.new(1e3,1e3,1e3)
    bodyp.D = 1.5e3
    bodyp.P = 1e3
    bodyp.position = targetPos
    bodyp.Parent = missile
    wait(1)

    bodyp.position = Vector3.new(targetPos.X,0,targetPos.Z)
    bodyp.D = 1.6e3
    wait(1)

    bodyp.Parent = Tool
    Tool.Handle.FlyingSound:Stop()
end


function onActivated()
    if not enabled  then
        return
    end

    enabled = false


    local character = Tool.Parent;
    local humanoid = character.Humanoid
    if humanoid == nil then
        print("Humanoid not found")
        return 
    end

    targetPos = humanoid.TargetPoint
    lookAt = (targetPos - character.Head.Position).unit

    fire(lookAt)

    wait(1)

    enabled = true

end

function onTouched(part)
    local h = part.Parent:FindFirstChild("Humanoid")
    if h ~= nil and Tool.Parent == game.Workspace then
        Tool.Handle.FlyingSound:Stop()
        bodyp.Parent = Tool
        --Tool.Parent = h.Parent
    end

end

Tool.Handle.Touched:connect(onTouched)
script.Parent.Activated:connect(onActivated)


Answer this question