Vaelkarr
(vael)
April 2, 2020, 11:41pm
#1
So basically, I wanted to make your character move using a script, but it wouldn’t work and it never sent an error. I have been trying to find some other ways but it is on NPC only.
Is there an alternate way of doing this?
Example :
player.Character.Humanoid:MoveTo(pos)
Thanks, Vaelkarr.
C_Sharper
(Sharpie)
April 2, 2020, 11:43pm
#2
Your example should work fine.
Could you post the code you tried using?
1 Like
Vaelkarr
(vael)
April 2, 2020, 11:46pm
#3
I tried using
game.ReplicatedStorage.OnPressed.OnServerEvent:Connect(function(p)
p.Character.HumanoidRootPart.CFrame = CFrame.new(408.5, 59.928, -408.57)
p.Character.Humanoid:MoveTo(Vector3.new(348.56, 61.444, -409.55))
end)
C_Sharper
(Sharpie)
April 2, 2020, 11:55pm
#4
Can you confirm this code does execute properly? If not, you could add a print
statement at the top to make sure it fires.
Vaelkarr
(vael)
April 2, 2020, 11:56pm
#5
Well, the player is getting teleported because of the second line, so I can confirm that it is firing.
C_Sharper
(Sharpie)
April 2, 2020, 11:58pm
#6
You could try commenting out the first line to see if :MoveTo
works at all
Vaelkarr
(vael)
April 3, 2020, 1:32am
#7
I tried that, it still printed, but it didn’t move my character.
1 Like
Does it work if you run :MoveTo
client-sided?
Vozcom
(Vozcom)
April 3, 2020, 2:46am
#9
I use this way:
local char = player.Character or player.CharacterAdded:Wait()
char:SetPrimaryPartCFrame(posCFrame)
Make sure to set the character’s PrimaryPart to its HumanoidRootPart, so the script would looks like this:
local char = player.Character or player.CharacterAdded:Wait()
char.PrimaryPart = char.HumanoidRootPart or char.Torso
char:SetPrimaryPartCFrame(posCFrame)
Operatik
(Operatik)
April 3, 2020, 4:48am
#10
You should probably freeze character movements before automatically moving the player. Or else they’ll cancel it.
You can use context action service to do this fairly cleanly.
The following works because ContextActionService works on a priority system. If a higher priority action is bound, it will sink input before filtering down to other actions. It also marks the input action as gameProcessed when checked against some UserInputService functions such as InputBegan.
At the current time, the default control scripts use UserInputService and check if the gameProcessed flag is false before moving your charact…
However, I think client-sided moving method is not a biggie, honestly.
@Vozcom I don’t think that’s necessary, because the player fires a remote from client of some sort, thus the character should always exist after that.
Vaelkarr
(vael)
April 3, 2020, 4:59am
#11
I mean on your player character, not on an NPC character.