Player controls not enabling back in a different script

Hello. I’m making a system that checks for a tool inside of a players backpacks and asks them if they want to remove it. It activates upon touching an invisible area around the trashcan and prompts the user with a GUI while freezing their movement. Issue is that once the player closes the GUI it doesn’t enable their movement back. What’s the issue? Do I need to check that the movement has been disabled on the script that enables it?

GUI PROMPTING SCRIPT

local player = game:GetService("Players")
local trash = game.Workspace.TrashDetector
local gui = player.LocalPlayer.PlayerGui.CardDelete.Frame
local playerModule = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
local controls = playerModule:GetControls()
local touched = false

trash.Touched:Connect(function()
	if touched == false then
		gui.Visible = true
		controls:Disable()
		wait(2)
		touched = true
	else
		touched = false
	end
end)

GUI SCRIPT

local TextButton = script.Parent
local gui = script.Parent.Parent
local player = game:GetService("Players").LocalPlayer
local playerModule = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
local controls = playerModule:GetControls()

TextButton.MouseButton1Click:Connect(function()
	local Character = player.Character or player.CharacterAdded:Wait()
	local Backpack = player:FindFirstChild("Backpack")
	local Card = Backpack:FindFirstChild("Lottery Card") or Character:FindFirstChild("Lottery Card")
	if Card then
		controls:Enable()
		Card:Destroy()
		gui.Visible = false
	else
		gui.Visible = false
	end
end)

picture of explorer (the other script is inside of StarterGui):
image

1 Like

after a bit of research using ContextActionService helped me out.

Here’s what I used:

local cas = game:GetService("ContextActionService")
--\\BIND ACTION//--
cas:BindActionAtPriority("DisableControls", function()
			return Enum.ContextActionResult.Sink
		end, false, Enum.ContextActionPriority.High.Value, unpack(Enum.PlayerActions:GetEnumItems()))
--\\UNBIND ACTION//--
cas:UnbindAction("DisableControls", function()
			return Enum.ContextActionResult.Sink
		end, false, Enum.ContextActionPriority.High.Value, unpack(Enum.PlayerActions:GetEnumItems()))

I’m pretty sure there’s a better way to do this as I got this from another forum post but that’s just what worked for me.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.