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

Is there a way to make your character spawn by pressing a key?

Asked by
Tizzel40 243 Moderation Voter
6 years ago

Like you character dies and you have to press space or r to respawn.also can it work for a button to?

2 answers

Log in to vote
0
Answered by 6 years ago

you can use a variation of the below code, detects a keyboard input and reacts to the input: (UserInputService)

local UserInputService = game:GetService('UserInputService')

function onInputBegan(input,gameProcessed)
    if input.KeyCode == Enum.KeyCode.Up then
        -- Up arrow 
    end
end

UserInputService.InputBegan:connect(onInputBegan)

other keys (including r) can be found here

Ad
Log in to vote
-2
Answered by
royee354 129
6 years ago

Use a local script Insert a Vector3 Value inside of the script

Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
repeat wait() until Player.Character
Character = Player.Character
Character.Humanoid.Died:connect(function(died)
Character.Torso.Position = script.Value.Value
Mouse.KeyDown:connect(function(key)
if key == "r" then
player:LoadCharacter()
end
end)
end)

Try this

0
Forget about the vector 3 value not needed royee354 129 — 6y
0
Add a wait before the load character thingy royee354 129 — 6y
2
Down vote for using deprecated APIs. evaera 8028 — 6y

Answer this question