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

How do i make a block that push's me back when i touch it?

Asked by 3 years ago
function onTouch()
    local Player = game.Players.LocalPlayer
    local c = Player.Character
    local BV = Instance.new("BodyVelocity")
                    BV.maxForce = Vector3.new(25000,25000,25000)
                    BV.Velocity = c.HumanoidRootPart.CFrame.lookVector*40
                    game.Debris:AddItem(BV,0.5)
                    BV.Velocity = BV.Velocity + Vector3.new(0,15,0)
end
script.parent.Touched:connect(onTouch)

this is the script i used but i didnt seem to work

any help is apreciated

2 answers

Log in to vote
0
Answered by 3 years ago

Alright man. If you've ever seen a killbrick you should be able to use Itzlewis' answer to solve your problem. But I'll give you how to get the player from the server side.

function onTouch(hit) -- hit is the part that touched
    local hum = hit.Parent.Humanoid -- checks for a humanoid. if not found, returns nil
    if hum then -- makes sure the humanoid was found
        local c = hum.Parent -- this is also the Player's character
        local BV = Instance.new("BodyVelocity", PARTYOUWANT) -- replace "PartYouWant" with the proper parent, like Itzlewis said. I think you want c.HumanoidRootPart, but idk.
        BV.maxForce = Vector3.new(25000,25000,25000)      -- it's just your code after this                  
        BV.Velocity = c.HumanoidRootPart.CFrame.lookVector*40
            game.Debris:AddItem(BV,0.5)
                BV.Velocity = BV.Velocity + Vector3.new(0,15,0)
    end
end

script.parent.Touched:connect(onTouch)  

And yeah that's it. You should be able to get the player from the server side because touched gives the touching part automatically as the first parameter. If you don't know what i mean by that, i highly recommend you look at this: https://developer.roblox.com/en-us/api-reference/event/BasePart/Touched

Thank you. Any problems you can reach out to me via discord (BlobMaster#8156) or you can message me on roblox. pls only message me if you have a problem relating to this question, though the code i gave you should fill your needs. Till next time.

Ad
Log in to vote
1
Answered by 3 years ago

You are not parenting the BodyVelocity. You should do BV.Parent = game.workspace.NAME OF THE PART YOU WANT TO PUSH U BACK

Also, make it a server script. You cannot have local scripts in workspace.

0
yeah but like how do i make it server side? soreno2468 31 — 3y
0
you make it a script Itzlewis99 26 — 3y
0
Well but itzlewiz in server scripts you cant do game.Players.LocalPlayer Nistrict 44 — 3y

Answer this question