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

My script stops working after I die.?

Asked by 6 years ago

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)
0
key down is deprecated starmaq 1290 — 6y
0
it didnt work. after i die the script still stopped: ChinesePenguware 7 — 6y
0
Is this the whole script? Rheines 661 — 6y
0
it is ChinesePenguware 7 — 6y

1 answer

Log in to vote
0
Answered by
Norbunny 555 Moderation Voter
6 years ago

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

Ad

Answer this question