ServerScriptService Script not deleting a string value in server storage

Hi Everyone,

I could not find any solution online so I figured I would ask you all. I am working on a minigame, where the following code executes once the player completes a level.

Essentially, once the round time is over, the game will loop through a folder in server storage (found that a folder works better than a table), and any players who have a string value with their Name in that folder will be killed (the value instance’s name is named after the player name, and values are created every time a new round starts). Whenever they pass a round, a function containing the following code is executed to make them “survive” that round and remove their string value so they are not killed.

However, the string values are not being deleted for some reason, and I would appreciate any assistance on why it is not. The if statement does execute and prints the statement nested in it, so I can confirm the script found the instance from the FindFirstChild. However, every time I playtest, and check the server’s view, the value is not being deleted which is puzzling me. Note that there is no error in the output

Below is the affected code.

local ServerStorage = game:GetService("ServerStorage")
local ValuesFolder = ServerStorage.Values
local playerInLevel = ValuesFolder.playersInLevel

if playerInLevel:FindFirstChild(player.Name) then
	playerInLevel:FindFirstChild(player.Name):Destroy()
	print("Removing "..player.Name.." from the Level")
	--PlayersSurvived += 1
end

Perhaps something revives the instance when it gets destroyed or there are multiple instances with the same name/configs under the same folder at once?

You can try checking for revivals in the following way:

game.ServerStorage.Values.playersInLevel.ChildAdded:Connect(function(child)
	print(child)
end)

If this prints an identical copy of the instance when you try to destroy it, then a script is cloning the instance a bit before destruction and adds it back, reversing what you did.

Sorry for the late reply!

So I have checked today and noticed that when the round starts, there are two instances of the string value.

I downloaded a copy of the game version from a month ago when this error was not a problem and the game ran perfectly fine. However, the error is still happening here.

Did something change with Roblox’s speed when executing scripts? The error is super complicated, but it is only caused because an if statement (this if statement creates a new instance) is executed before my script initially makes the instances.

EDIT: Found the bug! Thanks for the help.

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