this is the script:
PlayerName = tostring(game.Players.LocalPlayer.Name) speed = Instance.new("BodyThrust", workspace[PlayerName].HumanoidRootPart) local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() Mouse.KeyDown:connect(function(key) if key:byte() == 118 then speed.Force = Vector3.new(0, 0, -4000) end end) Mouse.KeyUp:connect(function(key) if key:byte() == 118 then speed.Force = Vector3.new() end end)
First of all, you might wanna just do the following:
local player = game:GetService("Players").LocalPlayer local character = player.Character
It's better to use Player.Character rather than that.
And you might also wanna use UserInputService instead. Make sure that the script is cloned to the player once you die. E.g. place it in the StarterGui
Corrected script:
-- services local inputService = game:GetService('UserInputService') local players = game:GetService("Players") -- https://developer.roblox.com/api-reference/class/UserInputService -- variables local player = players.LocalPlayer local speed = Instance.new('BodyTrust') wait(1) -- debug, letting the character load speed.Parent = Player.Character() -- functions userInput.InputBegan:Connect(function(input, gameProcessedEvent) if(gameProcessedEvent) then return end -- if they're typing in a chat or GUI, do nothing. if(Input.KeyCode == Enum.KeyCode.YourKey) then speed.Force = Vector3.new(0,0, - 4000) end end) userInput.InputEnded:Connect(function(input, gameProcessedEvent) if(gameProcessedEvent) then return end -- if they're typing in a chat or GUI, do nothing. if(Input.KeyCode == Enum.KeyCode.YourKey) then speed.Force = Vector3.new(0,0, 0) end end) -- events
Reminder to place the script in a parent which that reloads the script when you die, like I've stated before, the StarterGui