Scripts break after reset

That’s it, that’s the title.
I’m enabling them from my main menu script after it gets destroyed with this:

local scriptsFolder = game.Players.LocalPlayer.Character:WaitForChild("Scripts")
local scripts = scriptsFolder:GetChildren()
-- Few lines down...
for i, v in pairs(scripts) do
            if v:IsA("LocalScript") then
                v.Enabled = true
            end
        end

I tried using a separate enabler script:

local SCRIPTS = script.Parent.Scripts:GetChildren()

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
repeat task.wait() until character:FindFirstChild("Humanoid")
local humanoid = character:WaitForChild("Humanoid")

player.CharacterAdded:Connect(function()
    for i, v in pairs(SCRIPTS) do
        if v:IsA("LocalScript") then
            v.Enabled = true
        end
    end
end)

but this didn’t seem to work. No idea how to fix this.

Here’s an image of the explorer:
image

I feel like the solution is going to be extremely simple and I’m just blind or overlooking something right in front of me.
Thank you anyways

1 Like

Are you receiving any errors in the output?

One thing to point out, I don’t think you need the CharacterAdded event, as well as the player variable, since the script is automatically parented to the character, and would basically rerun when the character respawns. Try removing it and see if that could fix the issue.

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local scripts = character:WaitForChild("Scripts")

for i, v in pairs(scripts:GetChildren()) do
	if v:IsA("LocalScript") then
		v.Enabled = true
	end
end
1 Like

If you reset, your character will reset & respawn, and so will any scripts you have inside of ‘StarterCharacterScripts’

The enabler gets added after the character is added meaning that it can’t do CharacterAdded, since it already exists!

I suggest moving it into ‘StarterPlayerScripts’ to prevent this, or just removing the CharacterAdded portion in general!

1 Like

this brings up an infinite yield in the output Players.Foxxive.PlayerGui.Menu.Buttons.Canvas.MainFrame.Play.Button:WaitForChild("Humanoid")

The old code doesn’t, for some reason

I did, and adjusted the code a little:

local player = game:GetService("Players").LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")

local SCRIPTS = character:WaitForChild("Scripts"):GetChildren()

player.CharacterAdded:Connect(function()
	for i, v in pairs(SCRIPTS) do
		if v:IsA("LocalScript") then
			v.Enabled = true
		end
	end
end)

now this brings a new error:
image

1 Like

The code I gave was meant to be put in the script parented to StarterCharacterScripts

The error I gave happened with the script parented to StarterCharacter
It returns an infinite yield which it shouldn’t, I don’t know why it does

Nevermind, I just messed something up lol
It does work, but some of the scripts now only work AFTER I reset. The camera bobbing script is the first one I noticed

The error message you gave says the error occurred from a script in PlayerGui. Or your code is mentioning something in PlayerGui for some reason.
Could you please show your current code in the script parented to StarterCharacterScripts?

I literally just copy pasted your code in the wrong place, which is why the infinite yield happened, that’s a mistake on my end.

I’m not quite sure about this, but maybe it could be something to do with those scripts themselves. Check to see if the scripts are even enabled in-game from the properties tab.

None of the scripts are enabled initially, which is a bit odd.
Here’s a video I took to show my point

I am not sure if this would work as I haven’t tried this yet, but try converting the LocalScript (that enables all the other scripts) into a Server Script, and paste the code in it.

how would I go about that? As far as I’m aware there is no way to access a player’s scripts through the server. I could be wrong (and I most likely am) but I genuinely have no idea

What I meant was to use a Server Script instead of a LocalScript to enable the other LocalScripts. Make sure to paste the exact same code I have given and that it is parented to StarterCharacterScripts.

Also, maybe add a task.wait() (any amount of seconds) as it may take some time for the scripts to load.[/spoiler]

yes I know what you meant, I’m just unsure how to accomplish it. I’m not experienced with server stuff outside of remotes and basic game systems.
Unless I don’t know what you meant, and to use a server script INSIDE starter character

Okay, I did the latter and used a server script inside of startercharacter, which changed nothing. I added a task.wait above the v.Enabled in the loop for good measure. Again, nothing changed. Same result

To fix your issue use this code:

local player = game:GetService("Players").LocalPlayer
local humanoid

if player.Character then
    humanoid =  player.Character:WaitForChild('Humanoid')
    for i, v in pairs(player.Character:WaitForChild("Scripts"):GetChildren()) do
		if v:IsA("LocalScript") then
			v.Enabled = true
		end
	end
end


player.CharacterAdded:Connect(function()
    humanoid =  player.Character:WaitForChild('Humanoid')
	for i, v in pairs(player.Character:WaitForChild("Scripts"):GetChildren()) do
		if v:IsA("LocalScript") then
			v.Enabled = true
		end
	end
end)

The original problem was the fact you were getting the SCRIPTS only once! meaning if someone were to reset the children would come back as ‘nil’ or parentless meaning they were useless or non-functional.

yes, I solved the issue partially already. The code works, and as I mentioned in an older reply, the only script that doesn’t work upon playing (for some reason) is the camera bobbing effect that only works after a death or reset

Glad I was able to help! A camera bobbing script may have to be reset or re-activated every time someone resets or respawns, I’m not sure how yours work so it is hard to help you. If you would like to give more context I will try to help you as much as I can!

i did solve it eventually. I just disabled it manually from a separate script and enabled it once everything else was where it was supposed to

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