Re-Enabling a Script Doesn't Work

Damn all of this for a single property about scripts. Sorry if I’m wasting your time.

Alright, here’s an example:

Server Script:

local Event = game:GetService("ReplicatedStorage"):WaitForChild("EventNameHere")
local debounce = false

Event.OnServerEvent:Connect(function(player)
    if debounce then return end
    debounce = true
   
    -- rest of the code here
end)

Client Script:

-- add to the local script code that you gave above

local LocalPlayer = game:GetService("Players").LocalPlayer
local Event = game:GetService("ReplicatedStorage"):WaitForChild("EventNameHere")

LocalPlayer.Chatted:Connect(function(msg)
     Event:FireServer()
end)

You can do something like this so you won’t have to re-enable the server script anymore.

Let me try real quick. I’ll let you know the results.

1 Like

Alright sorry for the late reply, I couldn’t get my head around it for a long time because tiny brain. It seems like the “can only open it, once it teleports near you” part is good for now although like I’ve said, I only want to be able to teleport the box near me once. Since the script cannot be destroyed since it still needs connection to the Remote Event, how can I do it?

You can still delete the local script, you don’t have to do anything to the server script.

wait if maybe I can destroy the script, using the Server Script inside the box, it can happen but how would I reach Player’s PlayerGui with a Server Script?

You can, but it’s highly impractical since client changes don’t get replicated to the server, so if you make any changes to your UI or script on the client, the server will not be affected. (e.g, deleting a script on the client won’t delete it from the server)

No I meant like like you’ve just said, make the Server Script delete the Local Script instead of Local one doing it to the Server one.

Also the game is a 1 player game, if you can take advantage over that.

You don’t need to delete the local script from the server, you can just do script:Destroy() in the local script.

Plus clients cannot even delete the server scripts.

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()
			
			local LocalPlayer = game:GetService("Players").LocalPlayer
			local Event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

			LocalPlayer.Chatted:Connect(function(msg)
				Event:FireServer()
				
			end)
			
			script:Destroy()
			
		end
		
	end
	
end)

Here is the current Local Script. If I put the “script:Destroy()” code in it, would it still register the other script? Because I’ve tried putting it under the “end” of the “FireServer” statement and it did not work. I was able to teleport the box once, yes but after that I couldn’t write the keyword to open the box.

local Event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
local debounce = false

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

Event.OnServerEvent:Connect(function(player)
	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)

this is the Server Script btw.

Change the script to this:

local offset = Vector3.new(0, -2, -5)
local root = game:GetService("Players").LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local ToolBox = game.Workspace:WaitForChild("DebugTool-Box")
local userInputService = game:GetService("UserInputService")

local tpDebounce = false

userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.I then
            if tpDebounce then return end
            tpDebounce = true 

			print("Succefully called DeBox!")
			ToolBox:SetPrimaryPartCFrame(root.CFrame * CFrame.new(offset) * CFrame.Angles(0, math.rad(180), 0))
			ToolBox.Base.DropSound:Play()
		end
	end
end)

local LocalPlayer = game:GetService("Players").LocalPlayer
local Event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

LocalPlayer.Chatted:Connect(function(msg)
    if msg ~= "open" then return end
    if not tpDebounce then return end

    Event:FireServer()
    script:Destroy()
end)
1 Like

That just broke it completely. I could tp the box multiple times, I could open the box even though I wanted it to be able to open after the tp happens. I’m gonna try something real quick.

I added a debounce variable. Try the new version.

Again, I can tp it only once but now I can’t open the box by writing the keyword.

Are you sure you copied the new version?
It should work.

Wait I might’ve figured it out actually.

You probably entered the wrong keyword, it’s “open” not “Open”.

Alright here we go. You just did a tiny spelling mistake by writing “open” instead of “Open”. Wow man, I can’t believe you actually helped me all the way through I’m really thankful. I’ll make sure to credit you in the model one way or another lol.

1 Like