Hi devs I want to make a script where a player moves in the opposite direction they are facing with a bodyforce there are no errors but I do not move when I activate the code
local camera = game.Workspace.CurrentCamera
local plr = game.Players.LocalPlayer
local speed = 10
local char = plr.Character
local myHRP = char:WaitForChild("HumanoidRootPart")
local Tool = plr.Backpack:WaitForChild("SuperShotgun")
local bodyForce = Instance.new("BodyForce")
Tool.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
print("running")
local postpos = myHRP.Position +((myHRP.Position - camera.CFrame.p).unit * speed)
bodyForce.Parent = myHRP
bodyForce.Force = bodyForce.Parent.CFrame:vectorToWorldSpace(postpos)--line13
print(postpos)
wait(7)
bodyForce:Destroy()
bodyForce = Instance.new("BodyForce")
end)
end)
Players already have network ownership over their character so this isn’t relevant. It’s perfectly fine to do what OP is doing in this case.
I ended up messing around with your script a bit and got it working. I will say though that the player has to jump for the force to work well sometimes. I guess the legs/feet have a lot of friction by default?
local camera = game.Workspace.CurrentCamera
local plr = game.Players.LocalPlayer
local speed = 5000
local char = plr.Character or plr.CharacterAdded:Wait()
local myHRP = char:WaitForChild("HumanoidRootPart")
local Tool = script.Parent
local bodyForce = Instance.new("BodyForce")
Tool.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
print("running")
local camCFr = camera.CFrame
bodyForce.Force = camCFr.Position + (camCFr.LookVector * -speed)
bodyForce.Parent = myHRP
wait(1)
bodyForce.Parent = nil
end)
end)
Note I did change the Tool, speed, char, and the delay for getting rid of the BodyForce. Feel free to make them what you want though.