game.Players.PlayerAdded:Connect(function(player)
while true do
if player.Character:WaitForChild("HumanoidRootPart").CFrame.Y <= game.Workspace.FallenPartsDestroyHeight.Value + 50 then
player.Character.HumanoidRootPart.Cframe = CFrame.new(-98.57, 125.885, 17.1)
end
end
player.Character:MoveTo()
end)
Why isn’t this working? no errors but player is dying in void
I took this script into studio and found multiple errors that I noted bellow:
game.Players.PlayerAdded:Connect(function(player)
while true do -- will exhaust the server and not run
if player.Character:WaitForChild("HumanoidRootPart").CFrame.Y <= game.Workspace.FallenPartsDestroyHeight.Value + 50 then -- Value is not a child of FallenPartsDestroyHeight, also the server will have trouble finding player.Character
player.Character.HumanoidRootPart.Cframe = CFrame.new(-98.57, 125.885, 17.1) -- Capitalize "CFrame"
end
end
player.Character:MoveTo() -- You need a value here
end)
Here’s the modified code that will not have any errors, you can modify it to your liking:
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
while wait(.1) do
if char:WaitForChild("HumanoidRootPart").CFrame.Y <= game.Workspace.FallenPartsDestroyHeight + 50 then
char.HumanoidRootPart.CFrame = CFrame.new(-98.57, 125.885, 17.1)
end
end
-- I got rid of the :MoveTo() function completely since it didn't do anything
end)
end)
local run = game:GetService("RunService")
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local hrp = character:WaitForChild("HumanoidRootPart")
while true do
run.Stepped:Wait()
if hrp.Position.Y <= workspace.FallenPartsDestroyHeight + 50 then --FallenPartsDestroyHeight is a property, you cannot index its "Value" property as it doesn't exist.
character:PivotTo(CFrame.new(100, 125, 20)) --Use cleaner values here.
end
end
end)
end)
Added some comments which should help explain what you did wrong.
-500, if i add a print statement it still doesnt run
local run = game:GetService("RunService")
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local hrp = character:WaitForChild("HumanoidRootPart")
print(game.Workspace.FallenPartsDestroyHeight)
while true do
print(player.Character.CFrame.Y)
run.Stepped:Wait()
if hrp.Position.Y <= workspace.FallenPartsDestroyHeight + 50 then --FallenPartsDestroyHeight is a property, you cannot index its "Value" property as it doesn't exist.
character:PivotTo(CFrame.new(100, 125, 20)) --Use cleaner values here.
end
end
end)
end)
I figued it out, I need to say hrp.Cframe.Y
also is there a way to keep character from changing rotation? because it goes to default rotation when it spawns back in.
local run = game:GetService("RunService")
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local hrp = character:WaitForChild("HumanoidRootPart")
print(game.Workspace.FallenPartsDestroyHeight)
while true do
run.Stepped:Wait()
if hrp.Position.Y <= workspace.FallenPartsDestroyHeight + 50 then --FallenPartsDestroyHeight is a property, you cannot index its "Value" property as it doesn't exist.
character:PivotTo(CFrame.new(0, 50, 0)) --Use cleaner values here.
end
end
end)
end)
local run = game:GetService("RunService")
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local hrp = character:WaitForChild("HumanoidRootPart")
print(game.Workspace.FallenPartsDestroyHeight)
while true do
run.Stepped:Wait()
if hrp.Position.Y <= workspace.FallenPartsDestroyHeight + 50 then --FallenPartsDestroyHeight is a property, you cannot index its "Value" property as it doesn't exist.
hrp.Position = Vector3.new(0, 50, 0)
end
end
end)
end)
If you want to maintain orientation only alter/modify the position. Change the position I used to any you desire.