✓ Accepted answer
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:
local inputService = game:GetService('UserInputService')
local players = game:GetService("Players")
local player = players.LocalPlayer
local speed = Instance.new('BodyTrust')
wait(1)
speed.Parent = Player.Character()
userInput.InputBegan:Connect(function(input, gameProcessedEvent)
if(gameProcessedEvent) then return end
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(Input.KeyCode == Enum.KeyCode.YourKey) then
speed.Force = Vector3.new(0,0, 0)
end
end)
Reminder to place the script in a parent which that reloads the script when you die, like I've stated before, the StarterGui
5 comments
key down is deprecated
here you go https://www.youtube.com/watch?v=_gI-a2iSAnw
it didnt work. after i die the script still stopped:
Is this the whole script?
it is