Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does my ContextActionService mobile button disappear when the player resets?

Inside of a LocalScript, there is a function that I used :BindAction() on set to create a mobile button as well as look for input from 'Z'. It works and does its job up until the point where the player respawns. The mobile button no longer appears when the player respawns, but pressing 'Z' on a desktop platform still triggers the function and dies its job.

Any idea of what I'm doing wrong? Please note that the code is in a LocalScript that starts in StarterGui before the game starts.

local repstor = game:GetService("ReplicatedStorage")
local func = repstor:WaitForChild("RemoteFunction")
local conser = game:GetService("ContextActionService")
local st = false
local fir = false

local player = game.Players.LocalPlayer
local char = player.Character
if not char or char.Parent == nil then
    char = player.CharacterAdded:wait()
end
local hum = char:FindFirstChild("Humanoid")
print('loaded local slide')
function slideZ(str, state, obj)
	if st == false and state == Enum.UserInputState.Begin then
		st = true
		local t = func:InvokeServer("SlideAnim")
		repeat wait() until t == true
		if t == true then
			print('finished slide')
			st = false
		end 
	end
end


conser:BindAction("Slide", slideZ, true, "z")

1 answer

Try not renaming contextActionService

local repstor = game:GetService("ReplicatedStorage") local func = repstor:WaitForChild("RemoteFunction") local contextAction = Game:GetService("ContextActionService") local st = false local fir = false local player = game.Players.LocalPlayer local char = player.Character if not char or char.Parent == nil then char = player.CharacterAdded:wait() end local hum = char:FindFirstChild("Humanoid") print('loaded local slide') function slideZ(str, state, obj) if st == false and state == Enum.UserInputState.Begin then st = true local t = func:InvokeServer("SlideAnim") repeat wait() until t == true if t == true then print('finished slide') st = false end end end contextActionService:BindAction("Slide", slideZ, true, "z")

This discussion is preserved as it was. New answers, comments, and votes are closed.