Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I anchor a character without the animation breaking?

Asked by
H3kken -4
4 years ago

I'm making a dialog for an information booth in my game, the dialog's parent is a head of a character which has the standard character animations. But I want the character to be sort of glued to the ground so players can't mess up the characters position. If I do script.Parent.HumanoidRootPart.Anchored = true the animation breaks. Has anyone fixed this before?

0
set the walk speed and jump power to 0 User#5423 17 — 4y
0
Try gluing the entire NPC to a wall. Or use Weld. PazVan800 -5 — 4y

1 answer

Log in to vote
-2
Answered by
Yuuwa0519 197
4 years ago
Edited 4 years ago

This works for me(local script)

local human = game.Players.LocalPlayer.Character
local defaultWalk = human.WalkSpeed -- defines the walkspeed(how fast humanoid walks)
local defaultJump = human.JumpPower -- defines the jumping power ( how much power to jump)
human.WalkSpeed = 0 --prevents player from walking by setting the speed to 0
human.JumpPower = 0 -- prevents player from jumping by making jumppower to 0
human.PrimaryPart.Anchored = true -- this looks unnecessary as you already setted walk and jump to 0, but this is important so the thing wont move when it is pushed by other thing

wait(5)--period of time for player being anchored

human.WalkSpeed = defaultWalk 
human.JumpPower = defaultJump
human.PrimaryPart.Anchored = false

if you want to access from normal script, add a new remoteevent named "freezePlayer" in replicatedStorage or wherever you want to go

--code

--code

--you come to point where you want to anchor the person
local freezePlayer = game.ReplicatedStorage:WaitForChild("freezePlayer") -- defines the freezePlayer event inside Replicated Storage
freezePlayer:FireAllClient() --fires the client(client is basically a player, so this is sending this event to all the client(Players) 

then, add this to local script(store local script inside starterPlayer > starterplayerscript

local freezeMe = game.ReplicatedStorage:WaitForChild("freezePlayer") -- waiting for the event to load to prevent from game to define something that still does not exist.

freezeMe.OnClientEvent:Connect(function() -- starts to run when the script( the one on above) fires the event

local human = game.Players.LocalPlayer.Character
local defaultWalk = human.WalkSpeed
local defaultJump = human.JumpPower
human.WalkSpeed = 0 
human.JumpPower = 0 
human.PrimaryPart.Anchored = true

wait(5)

human.WalkSpeed = defaultWalk 
human.JumpPower = defaultJump
human.PrimaryPart.Anchored = false
end)



I know that there is more faster ways to do it, but I am still a starter at scripting so sorry if these scripts is inefficient. Hope this works :D

0
Why are you spoonfeeding code? Mirzadaswag 110 — 4y
0
spoonfeeding incorrect code ... game.Players.LocalPlayer.Character in OnServerEvent -1 User#5423 17 — 4y
0
oops i think its OnClientEvent Yuuwa0519 197 — 4y
0
I appreciate your response and the fact that you're trying to help me. But like other people said. You're kind of spoonfeeding me code which is incorrect. This locks a player, not an NPC in the workspace like I asked for. Again, I appreciate your will to help me. But it's kind of useless. H3kken -4 — 4y
Ad

Answer this question