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

how do i set a custom respawn button?

Asked by 2 years ago

i have a main menu in my startergui that's scripted to spawn in as an elk (or any animal i have planned, but i only have the elk for now). it removes the player model, but when i reset the player doesn't respawn, the elk just perpetually stays there dead. so i wanted to script in a button for someone to press that respawns their player character, so they can click the button again and repeat the cycle.

here's my localscript, as you can see i have the userinputservice and my desired button defined at the top, i just can't find a way to get them to work, all the functions i wrote don't work

local MainMenu = script.Parent
local Player = game.Players.LocalPlayer
local PlayerModel = Player.Character
local uis = game:GetService("UserInputService")
local K = Enum.KeyCode.K
----------> BUTTONS
local ElkButton = MainMenu.MainFrame.SelHerbivores.Elk
----------> MODELS
local Elk = game.ReplicatedStorage.Animals.ElkMale.Adult
--------------------------------------------------------------------------------

ElkButton.MouseButton1Click:Connect(function(player)

    local SpawnElk = Elk:Clone()
    local OldModel = PlayerModel

    SpawnElk:SetPrimaryPartCFrame(OldModel.PrimaryPart.CFrame)

    Player.Character = SpawnElk
    SpawnElk.Parent = workspace

    PlayerModel:Remove()
    MainMenu:Remove()

end)

i tried stuff like

uis.InputBegan:Connect(function()
K = Elk:Remove()
K = Player:LoadCharacter()
end)

but that didn't work obviously

0
Try setting the workspace.CurrentCamera's CameraSubject to the Elk Humanoid. Also update the player model to the elk. AnonymousShadowDev 0 — 2y
0
here's what i changed: ( https://cdn.discordapp.com/attachments/905933934871846934/950857444807045170/unknown.png ) and here's the error message i got: ( https://cdn.discordapp.com/attachments/905933934871846934/950857541494128660/unknown.png ) is it because the PlayerModel:Remove() is interfering? hostileelf 0 — 2y
0
the respawn system works now, but it only spawns in the elk's model and you can't control it hostileelf 0 — 2y

Answer this question