Trying to work with Moveto:

  1. What do you want to achieve?
    Move the player to the Fireposition part

  2. What is the issue?
    I am getting the error;

Moveto is not a valid member of Humanoid “Workspace.nick2222.Humanoid”
Stack Begin - Studio
Script ‘Workspace.Fire.Script’, Line 5 - function fire
Stack End

  1. What solutions have you tried so far?
    I havent tried the Moveto function before so this is my first experience with it

Its very simple, i am wanting to make a cannon fire the players to a certain position. i originally had a bodyposition with maxforce and all that but it was just too frustrating to deal with(as in each test would result in different outcomes even if values didnt change). so i looked for an alternative and came across “Moveto”. this is what i tried:

function fire(hit)
	local c = hit.Parent
	if c:findFirstChild("Humanoid") then
		local h = c:findFirstChild("Humanoid") 
		h:Moveto(game.Workspace.FirePosition)
		wait(.1)

	end
end
script.Parent.Touched:connect(fire)

and this is the error im recieving:

Moveto is not a valid member of Humanoid “Workspace.nick2222.Humanoid”
Stack Begin - Studio
Script ‘Workspace.Fire.Script’, Line 5 - function fire
Stack End

1 Like

It’s MoveTo, not Moveto, simple typo, also if FirePosition is a part, give MoveTo the Position property of FirePosition because it expects a Vector3 and not an Instance

Also pretty minor, but use task.wait instead of wait as wait is outdated

@AustnBlox Fixed all the other minor stuff because you also used the deprecated connect and findFirstChild which were mostly minor but still good to know, though I wouldn’t use FindFirstChildWhichIsA in this case since you specifically only want a Humanoid, FindFirstChildOfClass would be better

2 Likes
function fire(hit)
    local c = hit.Parent

    if c:FindFirstChildWhichIsA("Humanoid") then
        local h = c:FindFirstChildWhichIsA("Humanoid")
        h:MoveTo(workspace.FirePosition)
          
        task.wait(0.1)
    end
end

script.Parent.Touched:Connect(fire)

I think you can use :PivotTo() instead of :MoveTo()

that seemed to fix the issue! thanks for the help and quick response :slight_smile: though i do have another question. the position the character is moving to is a distance away and its coming from a cannon on one side of the map to another, but when the player is in the air they stop moving. what can i do about that?

Can you use :PivotTo() instead of :MoveTo() when position the Humanoid to the ‘FirePosition’?

heres a screenshot for reference.

" PivotTo is not a valid member of Humanoid “Workspace.nick2222.Humanoid” "

ok so i did this

function fire(hit)
	local c = hit.Parent
	if c:findFirstChild("Humanoid") then
		local h = c:findFirstChild("Humanoid") 
		c:PivotTo(game.Workspace.FirePosition.CFrame)
	task.wait()

	end
end
script.Parent.Touched:connect(fire)

my only issue with this is its teleports the player. im not really looking for something that teleports the player, rather something that moves the player to the position if that makes sense

That I’m not sure exactly in your case since I assumed it was simple movement, now that I read the post correctly, maybe try ApplyImpulse on the Character’s HumanoidRootPart

And as a result you might need to make a deboucne system to prevent the code from working more than once instead of every .1 seconds

local debounce = true

function fire(hit)
    local c = hit.Parent

    if c:FindFirstChildOfClass("Humanoid") and debounce then
	    debounce = false
        local hrp = c.HumanoidRootPart
        hrp:ApplyImpulse(Vector3.new(0,0,0))
          
        task.wait(0.1)
		debounce = true
    end
end

script.Parent.Touched:Connect(fire)

Change the 0,0,0 around to numbers that’ll take you there, not sure of an exact way to get the velocity, might need to use some equations of motion probably, if that doesn’t work maybe try changing the AssemblyLinearVelocity property around since MoveTo isn’t really needed here and may be harder to do with MoveTo

3 Likes

You could try something like this when using :PivotTo() :

game.Players.PlayerAdded:Connect(function(Player)
     Player.CharacterAdded:Connect(function(Character)
         task.wait(5)
         Character:PivotTo(workspace.FirePosition.CFrame + Vector3.new(0, 3, 0))
    end)
end)

yessir this seemed to do the job. what i ended up doing was changing the assemblelinearvelocity, heres the code

‘’’’’’
local debounce = true

function fire(hit)
local c = hit.Parent

if c:FindFirstChildOfClass("Humanoid") and debounce then
	debounce = false
	local hrp = c.HumanoidRootPart
	hrp:ApplyImpulse(Vector3.new(896.202, 513.715, -732.992)) --Honestly idk if this even changes anything, as without the code below the script does nothing
	hrp.AssemblyLinearVelocity = Vector3.new(500, 300, 0)

	task.wait(0.1)
	debounce = true
end

end

script.Parent.Touched:Connect(fire)
‘’’’’’

EDIT: just wanted to make a small edit that i changed the vector on the hrp:ApplyImpulse line and it still worked the same. so its really based on the assemblylinearvelocity line i suppose

1 Like

If the ApplyImpulse line didn’t work then it’s best to use AssemblyLinearVelocity, not sure exactly how ApplyImpulse didn’t work since I never really used it, I mentioned it so you can have 2 possible solutions and I saw that ApplyImpulse is instant and good for explosions, but if AssemblyLinearVelocity works in your case then it’s all good

1 Like