Re-Enabling a Script Doesn't Work

Hello! Currently I’m trying to re-enable a script by using another script in-game but it doesn’t work at all. It shows as it is enabled but the script itself does nothing. One of the scripts is supposed to activate an ‘if’ statement (which is the script I’m trying to re-enable) and one of the scripts is supposed to enable that script (the other script is disabled by default).

Currently I’m trying use a method with the Remote Event. The Local Script inside the player’s PlayerGui fires that event. When the event fires, it activates the Server Script inside the ServerScriptService which is also the script that is supposed to re-enable the Server Script that’s inside a model.

I’ve tried other methods such as cloning the script from somewhere it wouldn’t activate, to the model itself, which also ended up in the same result.

I’m simply using the “.Enabled = true / .Disabled = false” code for enabling the script, I don’t know if there are any other methods of doing it.

Why not just listen to a BindableEvent or RemoteEvent?

1 Like

I mean I’ve already tried using the Remote Event, which did not work as I’ve said in my article. I’m currently searching what I could do with BindableEvent but I still have some suspicion left for it since Remote Event did not work.

Can you show us the code inside the scripts and give us more detail about the model?

Yeah I don’t think BindableEvent is going to do it since they only allow communication through server scripts. For further information, I have a model that teleports near the player when the player presses the ‘i’ key. The scripts that teleports the model is a Local Script, ofcourse. I somehow need to also re-enable the script I’ve been talking about when that ‘teleport’ command happens.

I’ll quickly make a video so you can understand better. I just thought the solution would be simple so I decided to explain it instead.

1 Like

You could solve this by copying your script into a spawned function; I am not sure why this might be failing you unless you are firing an object that doesn’t exist on the server ex:

-- LocalScript
local new_object = Instance.new("Part", workspace)
remote_event:FireServer(new_object) -- this will be nil to the sever

Your description does not sound like this is happening, though maybe you are firing the wrong remote event? StarterGUI is copied in to PlayerGUI so if the remote event is a child of StarterGUI it could be silently failing.

1 Like

easy fix is to just use an attribute and set it on the script when you want to disable it and watch in the script when the attribute is there


script:SetAttribute('DisableScript', true)  -- this would be the disable for the script

script:SetAttribute('DisableScript', nil)  -- this would be the enable.  just removes Attribute from the script together

then watch for the changes with getattributechangedsignal

script:GetAttributeChangedSignal('DisableScript'):Connect(function()
	if script:GetAttribute('DisableScript') then  -- this is when its disabled
		
	else
		  -- this is when its enabled again
	end
end)
1 Like

The Remote Event is the child of Replicated Storage (not anymore though because I had to delete the Remote Event method to show what I’m trying to do in the video).

I’m going to make sure to try it out although I want to send this video first so it is better to understand what the purpose is if that’s alright. I don’t want any misunderstandings whatsoever.

1 Like

Or maybe turn the script into a ModuleScript?

1 Like

Alright this is DeBox (Bad with names) and as seen in the video, I press the ‘i’ key to teleport it near me. When I type “Open” in chat, it does a tiny animation.

local debounce = false

local ToolBox = game.Workspace["DebugTool-Box"]

game.Players.PlayerAdded:Connect(function(player)
	
	player.Chatted:Connect(function(msg)
		
		if msg == "Open" then
			if debounce then return end
			debounce = true
			
			ToolBox.MessageInputter.Line.SurfaceGui.Enabled = false
			ToolBox.MessageInputter.Base.Sound.Volume = 0
			
			ToolBox.MessageInputter.Line.Waiting.Enabled = true
			ToolBox.Base.Searching:Play()
			ToolBox.MessageInputter.Line.Waiting.Message.Text = "."
			wait(1)
			ToolBox.MessageInputter.Line.Waiting.Message.Text = ".."
			ToolBox.MessageInputter.Base.Searching:Play()
			wait(1)
			ToolBox.MessageInputter.Line.Waiting.Message.Text = "..."
			ToolBox.MessageInputter.Base.Searching:Play()
			wait(1)
			
			ToolBox.MessageInputter.Line.Waiting.Enabled = false
			
			ToolBox.MessageInputter.Line.Successful.Enabled = true
			ToolBox.MessageInputter.Base.Successful:Play()
			ToolBox.Face.Screen.Happy.Enabled = true
			ToolBox.Face.Screen.SurfaceGui.Enabled = false
			
			wait(2)
			ToolBox.AnimationController:LoadAnimation(ToolBox.Opening):Play()
			ToolBox.Base.OpeningSound:Play()
			
			wait(2)
			ToolBox.MessageInputter.Line.Waiting.Enabled = true
			ToolBox.MessageInputter.Line.Successful.Enabled = false
			
			ToolBox.Face.Screen.Happy.Enabled = false
			ToolBox.Face.Screen.SurfaceGui.Enabled = true
			
			wait(4.5)
			
			ToolBox.MessageInputter.Line.SurfaceGui.Enabled = true
			ToolBox.MessageInputter.Base.Sound.Volume = 5
			ToolBox.MessageInputter.Line.Waiting.Enabled = false
			
			wait(1)
			debounce = false
			
		end
		
	end)
	
end)

^ This is the script that activates when I say the keyword in the chat. This is also the script I want to enable in-game when It’s disabled at first.

wait(2)

local offset = Vector3.new(0, -2, -5)

local root = game.Players.LocalPlayer.Character.HumanoidRootPart

local ToolBox = game.Workspace["DebugTool-Box"]

local userInputService = game:GetService("UserInputService")

userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	
	if input.UserInputType == Enum.UserInputType.Keyboard then
		
		if input.KeyCode == Enum.KeyCode.I then
			
			print("Succefully called DeBox!")
			ToolBox:SetPrimaryPartCFrame(root.CFrame * CFrame.new(offset) * CFrame.Angles(0, math.rad(180), 0))
			ToolBox.Base.DropSound:Play()
			script:Destroy()
			
		end
		
	end
	
end)

^ This is the script that teleports the box near me. I want this script to also somehow enable the other script. Also good thing to note is that this script is a Local Script and the other one is a Server Script inside the box.

The reason to why I want this script to enable the other script specificly, is because I don’t want to be able to make the box open itself UNLESS I tp it near me.

aha! the script is enabled and runs the problem is you are relying on a connection to have fired. PlayerAdded will be connected when re-enabled but it won’t have any players added unless they join after the script is enabled. Try doing the same script with existing players

for _, player in game.Players:GetPlayers() do
   player.Chatted:Connect(function(msg)
        -- ...
1 Like

Alright so, you’re using Players.PlayerAdded to detect if a player has chatted after they joined the game.

And since you’re disabling the script, the events will disconnect. Meaning, the script will only work for new players when it’s re-enabled.

Anyway, why do you want to disable the script in the first place?

If you are meaning the “script:Destroy” line, the reason is because I only want to be able to run the teleport script once.

How about instead of checking if a player has chatted on the server, you do it on the client?

Then, you can use a RemoteEvent to move the box with a script on the server.
Plus, you won’t have to re-enable the server script over and over again, you just have to fire the RemoteEvent.

1 Like

Could you possibly give a code / picture example? Sorry, I’m really bad at scripting in general and I don’t really know how to use Remote Events. I half looked up on Youtube for the last method.

Also thank you for letting me know, I didn’t know the difference I fixed that part now.

Nvm, I replaced the “game.Players.PlayerAdded:Connect(function(player)” part with that code and now that script doesn’t work in general as well.