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

Why does this fly script turn speed to nan?

Asked by
stepatron 103
5 years ago
Edited 5 years ago

I built upon a preexisting script (i forgot who) to resemble the one in Iron Man Simulator. Unfortunately when stopping/slowing down, the player's speed and position become nan.

01--// Services
02local UserInputService = game:GetService("UserInputService")
03local RunService = game:GetService("RunService")
04local Players = game:GetService("Players")
05 
06--// Service Objects
07local LocalPlayer = Players.LocalPlayer
08local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
09local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
10local CurrentCamera = workspace.CurrentCamera
11 
12--// Objects
13local BodyVelocity = Instance.new("BodyVelocity")
14BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
15BodyVelocity.Velocity = Vector3.new(0,0,0)
View all 81 lines...
0
Can you quote the line of code that the error shows up at? TheJellyNinja_XD13 62 — 5y
0
The script doesn't produce any errors, but the player's speed and position become nan. I believe this is because when xDelta and zDelta, the direction variable at line 41 becomes nan stepatron 103 — 5y

1 answer

Log in to vote
0
Answered by
stepatron 103
5 years ago
Edited 5 years ago

Figured it out

001-- Services
002local input = game:GetService("UserInputService"-- Gets input from player's keyboard
003local rs = game:GetService("RunService")           -- Handles the runtime of the game
004local camera = game.Workspace.CurrentCamera
005 
006-- Player
007local player = game:GetService("Players").LocalPlayer               -- Player
008local character                                                     -- Player's character
009local root                                                          -- Character's HumanoidRootPart
010local humanoid                                                      -- Character's Humanoid
011player.CharacterAdded:connect(function(Char)
012    character = Char
013    root = Char:WaitForChild("HumanoidRootPart")                   
014    humanoid = Char:WaitForChild("Humanoid")                   
015end)
View all 100 lines...
0
You can also try finding new scripts like this one repeat wait() until game.Players.LocalPlayer and game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character:findFirstChild("Torso") and game.Players.LocalPlayer.Character:findFirstChild("Humanoid") local mouse = game.Players.LocalPlayer:GetMouse() repeat wait() until mouse local plr = game.Players.LocalPlayer local torso = plr. Mrtixglitch2 -1 — 5y
Ad

Answer this question