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

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

Asked by
OniiCh_n 410 Moderation Voter
8 years ago

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

Log in to vote
0
Answered by
Dorx86 0
8 years ago

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")

Ad

Answer this question