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
9 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.

01local repstor = game:GetService("ReplicatedStorage")
02local func = repstor:WaitForChild("RemoteFunction")
03local conser = game:GetService("ContextActionService")
04local st = false
05local fir = false
06 
07local player = game.Players.LocalPlayer
08local char = player.Character
09if not char or char.Parent == nil then
10    char = player.CharacterAdded:wait()
11end
12local hum = char:FindFirstChild("Humanoid")
13print('loaded local slide')
14function slideZ(str, state, obj)
15    if st == false and state == Enum.UserInputState.Begin then
View all 27 lines...

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