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

This script is suppose to push the character back when you step on it, not working?

Asked by 5 years ago

I made as script so where, when you jump on a the object that you're touching, it's suppose to fling the character who touched it back. but for some reason it's not working, nor is it outputting errors. Help!

Local Script

script.Parent.Touched:Connect(function(hit)

    if hit.Parent:FindFirstChild("UpperTorso") then

        script.Parent.PushBack:FireServer(hit)

    end

end)

Server Script

    db = true

 script.Parent.PushBack.OnServerEvent:Connect(function(hit)

    if db then

        db = false

        local torso = hit.Parent.UpperTorso

        torso.Velocity = (torso.CFrame.lookVector) * -100

        wait(2)

        db = true

    end

end)



[

](https://gyazo.com/57e9c28f23aa7914662dace8f404c515)

0
LocalScripts will not run in the Workspace. DeceptiveCaster 3761 — 5y
0
@RobloxWhizYT Okay I fixed that, now it's outputting errors and it's talking about how torso is a nil value, even though my character is in R15 2.0 and has an UpperTorso... JayShepherdMD 147 — 5y
0
Try checking for the HumanoidRootPart instead of the UpperTorso. DeceptiveCaster 3761 — 5y
0
On the server Script on line three do "script.Parent.PushBack.OnServerEvent:Connect(function(Player,hit)" That player is always supposed to be there RedOverLoad9000 5 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Turns out I didn't even have to use a Remote Event, Server and Local Script at all. All I needed was a regular script and I just used BodyVelocity instead of Torso.

local debris = game:GetService("Debris")
db = false
script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("UpperTorso") then
        if not db then
            db = true
            local torso = hit.Parent.UpperTorso
            local bv = Instance.new("BodyVelocity",torso)
       bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
       bv.Velocity = torso.CFrame.lookVector * -500
       debris:AddItem(bv,0.5)
            wait(2)
            db = false
        end

    end
end)
Ad

Answer this question