Hello,
I have this problem where the character gets flung after the player walks while being teleported to a different position and I unanchor the humanoidrootpart.
Does anyone know how to fix this?
This is the script:
for i, player in pairs(game.Players:GetChildren()) do
player.Character:FindFirstChild("Humanoid").WalkSpeed = 0
player.Character.HumanoidRootPart.Anchored = true
end
for i = 5, 0, -1 do
Inter.Value = "Game starting in: "..i
task.wait(1)
end
for i, player in pairs(game.Players:GetChildren()) do
player.Character:FindFirstChild("Humanoid").WalkSpeed = 16
player.Character.HumanoidRootPart.Anchored = false
game.ReplicatedStorage.GuiEvent:FireClient(player)
end
Apparently there are new forces being applied to the player, try using:
-- Services
local Players = game:GetService("Players")
-- The Function to Start Game
function GameStart()
for _, Player in Players:GetPlayers() do -- Get the player
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
Humanoid:ChangeState(Enum.HumanoidStateType.Physics) -- Block Player to receive external forces
Humanoid.WalkSpeed = 0
coroutine.wrap(function() -- Do multiple tasks for Unlock all players at same time
for i = 5, 0, -1 do
task.wait(1)
print(i,"seconds")
if i == 0 then
UnlockPlayer(Humanoid); -- Fire function to unlock player after 5 seconds
warn("Game Started")
end
end
end)()
end
end
-- Function to Enable Player movement
function UnlockPlayer(Humanoid)
Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp) -- Return Humanoid to default State
Humanoid.WalkSpeed = 16
end
Players.PlayerAdded:Connect(GameStart) -- Fire function to start game
What script are you using to teleport the player? Simply using MoveTo() on the character should move the character to a given position, with no flinging.
For example, this code (in a LocalScript) should teleport the player to a given position with no flinging. Feel free to modify as needed for your game!
-- Get the player
local player = game.Players.LocalPlayer
-- Get the player's character
local character = player.Character
-- Check to see if they have a character
if character then -- If they do:
-- Teleport their character
character:MoveTo(Vector3.new(0,0,0)) -- Change the Vector3 values to whatever you like; this is your destination to teleport to
else -- But if they don't:
-- Warn in the output that the character doesn't exist.
warn("No character for player "..player.." exists!") -- This also tells us which player doesn't have the character.
end