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