Why does this script do nothing?

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.HumanoidRootPart.AssemblyLinearVelocity = (script.Parent.CFrame.UpVector * 200) + (script.Parent.CFrame.LookVector * 200)
	end
end)

It’s supposed to fling you off the map if you touch it. I checked it with print statements and it runs. Your character just doesn’t get moved anywhere. Why?

Is there the velocity object in the player? If not then it’s not gonna work

I didn’t put one in, so that’s a no. I tried re-using some code I had from a different level in the game:


local Parts = script:GetChildren()  -- this gets a table of parts
while true do

wait(3)
	for i , part in ipairs(Parts) do
			
		spawn(function()  
			script.UnionAudio.Click:Play()
			for i = 1, 7 do
		part.Orientation += Vector3.new(0,2.5,0)
			end
		end)
		end
wait(.8)
	for i , part in ipairs(Parts) do
		
		spawn(function()  
			script.UnionAudio.Click:Play()
			for i = 1, 7 do
				part.Orientation += Vector3.new(0,2.5,0)
			end
		end)
	end
	
	wait(.8)
	for i, part in ipairs(Parts) do
		
		spawn(function()
			script.UnionAudio["Slight Woosh"]:Play()
			local Num = 12
	for i = Num, 0, -1 do -- This means : Start at Num, go to 0, with a step of -1
		task.wait()

		part.Orientation += Vector3.new(0,25,0)
---------------------------------------------------------------------------------------------------
		for _, Touching in workspace:GetPartsInPart(part) do --This section
			if game.Players:GetPlayerFromCharacter(Touching.Parent) then
				Touching.Parent.HumanoidRootPart.AssemblyLinearVelocity = (part.CFrame.UpVector * 200) + (part.CFrame.LookVector * 200)
----------------------------------------------------------------------
			end
		end
	end
		end)
	
		
	end
	wait()
end

Requires NetworkOwnership with a yield in order to allow the server to apply the change in assembly linear ownership, and Humanoid platform stand to be turned on to disable the humanoids resisting the force.

See the reference place file to see how it could be done and comparisons with methods that do not work:

I don’t think that’s the issue, because the other thing I used this for (The code in one of the replies) works just fine with zero issues. I do have the part spinning around though. Could that be an issue?

There’s zero error messages with this by the way.

The add it in the player to make him get flinged

Network ownership is strange. You can try

  • Setting the network ownership of the character to the server temporarily (/ what @dthecoolest was talking about)
    OR
  • Adding the velocity in a LocalScript instead of a server

Something along the lines of this should work (second solution)

local canTouch = true
workspace.Object.Touched:Connect(function(part)
	local root:BasePart = part.Parent and part.Parent:FindFirstChild("HumanoidRootPart")
	if canTouch and root then
		canTouch = false
		root:ApplyImpulse((workspace.Object.CFrame.LookVector+workspace.Object.CFrame.UpVector)*100*root.AssemblyMass)
		task.wait(0.5)
		canTouch = true
	end
end)

Used this post as reference