Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how do i make the player jump backwards when touching an object?

i am try to make make it so when a player is touching a certain object, the player jumps backwards but the script I made is only making the player jump.

damagePlane = script.Parent

function damage(hit)
	local partParent = hit.Parent
	local humanoid = partParent:FindFirstChild("Humanoid")
	local player = game:GetService("Players"):GetPlayerFromCharacter(partParent)
	local character = player.Character
	local rootPart = player.Character:FindFirstChild("HumanoidRootPart")
	local direction = rootPart.CFrame + rootPart.CFrame.LookVector
	if player then
		humanoid.Jump = true
		player:Move(-direction, false)
	end
end

damagePlane.Touched:Connect(damage)

2 comments

0

It’s humanoid move, not player move

0

when I changed that i got this error message Workspace.(model that the damage plane is in).damagePlane.damage:12: attempt to perform arithmetic (unm) on CFrame

1 answer

You mean knockback right?

script.Parent.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid then
		if not humanoid.Parent.Torso:FindFirstChild("VectorForce") then
			local VectorForce = Instance.new("VectorForce")
			local Attachment = Instance.new("Attachment")
			
			VectorForce.Parent = humanoid.Parent.Torso
			Attachment.Parent = humanoid.Parent.Torso
			VectorForce.Force = Vector3.new(0,300,6000) ---You might need to change this
			VectorForce.Attachment0 = Attachment
			VectorForce.ApplyAtCenterOfMass = true
			humanoid.Jump = true
			game:GetService("Debris"):AddItem(VectorForce,0.5)
			game:GetService("Debris"):AddItem(Attachment,0.5)
		end
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.