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

Why isn't velocity working in a server, but it works in test mode?

Asked by
MrHerkes 166
7 years ago

So this script is a landmine script. It would launch a player's body up into the air. It works in test mode, but doesn't work in server mode. Error is at line 27.

math.randomseed(tick(1))
touch = true
canRemove = {"RightUpperLeg","RightUpperArm","LeftUpperLeg","LeftUpperArm"}

function onTouch(PART)
    if touch then
        touch = false
        --Variables--
        local char = PART.Parent
        local humanoid = char:FindFirstChild("Humanoid")

        --Explosion effect--
        local boom = Instance.new("Explosion", script.Parent)
              boom.Position = script.Parent.Position
              boom.BlastRadius = 0
              boom.BlastPressure = 0
        local boomSound = script.Parent:WaitForChild("Boom")
        boomSound:Play()

        --Find, and kill player--
        if humanoid ~= nil then
            humanoid.Health = 0
        end

        --Launches player's body into air--
        local torso = char:FindFirstChild("UpperTorso")
        if torso then
            torso.Velocity = Vector3.new(math.random(-50,50), 250, math.random(-50,50))
            torso.RotVelocity = Vector3.new(math.random(-50,50), math.random(-50,50), math.random(-50,50))
        else
            PART.Velocity = Vector3.new(math.random(-50,50), 250, math.random(-50,50))
            PART.RotVelocity = Vector3.new(math.random(-50,50), math.random(-50,50), math.random(-50,50))
        end

        if math.random() < 0.60 then
            for i = 1, 10 do
                wait()
                local children = char:GetChildren()
                local removeJoint = children[math.random(#children)]
                for _,name in pairs(canRemove) do
                    if removeJoint.Name:match(name) then
                        if removeJoint.Name == name then
                            removeJoint = char:FindFirstChild("RagdollConstraint"..name)
                        end
                        if removeJoint then
                            removeJoint:Destroy()
                        end
                        break
                    end
                end
            end
        else
            print("No limbs blown off.")
        end
        wait(1)
        touch = true
    end
end

script.Parent.Touched:connect(onTouch)
0
Is this a LocalScript or a normal Server Script? Mayk728 855 — 7y
0
Normal script inside a landmine part. MrHerkes 166 — 7y
0
I found that this is the only way to contact you MrHerkes; and I wanted to let you know that Ragdoll Engine does not ruin your mobile battery. I have played Ragdoll Engine in my iPhone 7 Plus since you created the game, and my battery has not been affected in any shape or form. I have both gamepasses, and enjoyed the game a lot. I think you’ve made an awesome game. Please bring back mobile. :) JoeyDynamite2014 0 — 5y
0
I would also like the say that it’s the responsibility of the mobile owner that they look after their battery. If their battery sucks, it’s not your fault. Most of my Roblox friends play your game on mobile, and enjoyed it thoroughly. I am saying all of this with the utmost respect, but bringing back the mobile version would bring back a large number of people to the game. Have a good day. JoeyDynamite2014 0 — 5y

1 answer

Log in to vote
0
Answered by 7 years ago

I think I may have figured out your issue.

math.randomseed(tick(1))
touch = true
canRemove = {"RightUpperLeg","RightUpperArm","LeftUpperLeg","LeftUpperArm"}

function Applyforce(par,vel)
    local Forc = Instance.new("BodyVelocity")
    Forc.Parent = par
    --wait(.1)
    Forc.Velocity = vel
    wait(.2)
    Forc:Destroy()
end

function onTouch(PART)
    if touch then
        touch = false
        --Variables--
        local char = PART.Parent
        local humanoid = char:FindFirstChild("Humanoid")

        --Explosion effect--
        local boom = Instance.new("Explosion", script.Parent)
              boom.Position = script.Parent.Position
              boom.BlastRadius = 0
              boom.BlastPressure = 0
        local boomSound = script.Parent:WaitForChild("Boom")
        boomSound:Play()

        --Find, and kill player--
        if humanoid ~= nil then
            humanoid.Health = 0
        end

        --Launches player's body into air--
        local torso = char:FindFirstChild("LowerTorso")
        for I, v in pairs(char:GetChildren()) do
            wait()
            if torso then
                local apf = coroutine.wrap(Applyforce)
                --torso.Velocity = Vector3.new(math.random(-50,50), 250, math.random(-50,50))
                --[[apf(torso, Vector3.new(math.random(-50,50), 250, math.random(-50,50)))
                torso.RotVelocity = Vector3.new(math.random(-50,50), math.random(-50,50), math.random(-50,50))
            else
                PART.Velocity = Vector3.new(math.random(-50,50), 250, math.random(-50,50))
                            PART.RotVelocity = Vector3.new(math.random(-50,50), math.random(-50,50), math.random(-50,50))]]
                if v:IsA("Part") or v:IsA("MeshPart") then
                    apf(v,Vector3.new(math.random(-50,50), 250, math.random(-50,50)))
                end
            end
        end

        if math.random() < 0.60 then
            for i = 1, 10 do
                wait()
                local children = char:GetChildren()
                local removeJoint = children[math.random(#children)]
                for _,name in pairs(canRemove) do
                    if removeJoint.Name:match(name) then
                        if removeJoint.Name == name then
                            removeJoint = char:FindFirstChild("RagdollConstraint"..name)
                        end
                        if removeJoint then
                            removeJoint:Destroy()
                        end
                        break
                    end
                end
            end
        else
            print("No limbs blown off.")
        end
        wait(1)
        touch = true
    end
end

script.Parent.Touched:connect(onTouch)

I tested this in a game and I figured out the issue is velocity itself and server latency. So I decided to make a coroutine using body velocity. And the result seemed to have worked in server.

Comment back if it works the way you want it to.

0
It kind of works, its just that if someone is lagging hard, there will be a delay. Anyways, that's the closest answer I got. Thank you. MrHerkes 166 — 7y
Ad

Answer this question