Title says it all, I’ll press the mobile reset button and it’ll reset me and It won’t reset me anytime after that. Here’s the script:
local player = game:GetService("Players").LocalPlayer
local character = player.Character
local contextActionService = game:GetService("ContextActionService")
function onButtonPress()
character.Head:Remove()
end
local mobilebutton = contextActionService:BindAction("Reset", onButtonPress,true)
contextActionService:SetPosition("Reset",UDim2.new(0.72,-25,0.20,-25))
contextActionService:SetTitle("Reset", "Reset")
Where is this script located? StarterCharacter, StarterPlayer, StarterGui? If its inside starterplayer then the character variable you have will not reset when you die meaning the new character that is spawned will not be referenced by character. You should either place this inside startercharacter or get the character when you call reset so that the character variable always references the most recent player character.
Also, I’m not sure why you aren’t just setting the humanoid’s health to 0 to kill them
I wouldn’t usually recommend using StarterGui for standalone scripts without any UI elements, because StarterPlayerScripts basically does the exact same thing in that case.
I would do something like this:
local Player = game.Players.LocalPlayer
local ContextAction = game:GetService("ContextActionService")
function ResetPlayerCharacter()
local character = Player.Character
if character and character:FindFirstChild('Humanoid') then
character.Humanoid.Health = 0
-- Simple Kill character
end
end
local ResetMobile = ContextAction:BindAction("Reset", ResetPlayerCharacter, true)
ContextAction:SetPosition("Reset",UDim2.new(0.72,-25,0.20,-25))
ContextAction:SetTitle("Reset", "Reset")
It’s very similar to your original code but if placed in a localscript in StarterCharacterScripts it should do everything you need it to.
I’d highly suggest that you kill the player on the server, not the client. You can do so by firing a remote event from the local script and receiving it in a server script.
Yes, in an end product you would handle stuff like this from the server. I stuck to the client just for ease of understanding:
function ResetPlayerCharacter()
local character = Player.Character
if character and character:FindFirstChild('Humanoid') then
ServerReset:FireServer(character.Humanoid)
-- Don't actually provide the humanoid on the client, let the server do that. This is just an example.
-- Request that the server kill the specified humanoid
end
end