Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why doesn't the folder update after destroying instances within it?

I'm creating a game in which you can spawn a sled which is then assigned to you. This way, you are only allowed to spawn one at a time. In order to help if you lose your sled, I've also added a gui in which the player can delete their sled so they can respawn a new one. However, when the sled is deleted through the gui, the player is unable to spawn another one. I'm not quite sure why this is the case, here's the code.

in the gui to delete the sled

local player = script.Parent.Parent.Parent.Parent

script.Parent.MouseButton1Click:Connect(function()
local descendants = workspace.sleds:GetDescendants() --this is probably unnecessary but it works
	for i, descendant in pairs(descendants) do
		if descendant:IsA("StringValue") then
			if descendant.Value == player.Name then
				descendant.Parent:Destroy()
			end
		end
	end
end)

and in the clickable regen buttons

local sled = game.ServerStorage:WaitForChild("sled_of_doom") --sled gets cloned to spawn

script.Parent.MouseClick:Connect(function(player) 
	game.Players:GetPlayerFromCharacter(player)
	local descendants = workspace.sleds:GetDescendants() --look through all existing sleds
		for i,v in pairs (descendants) do
			if v:IsA("StringValue") then
				if v.Value == player.Name then --if sled exists under players name already, do not spawn one
					return
				end
			end
		end

	local newsled = sled:Clone()
	newsled.Parent = workspace.sleds
	newsled.PrimaryPart = newsled:WaitForChild("eee")
	newsled:SetPrimaryPartCFrame(CFrame.new(script.Parent.Parent.Position.X, script.Parent.Parent.Position.Y + 5, script.Parent.Parent.Position.Z - 10))
	
	local owner = newsled.owner
	owner.Value = player.Name
			
	script.Parent.Parent.Color = Color3.new(26,27,28)
	wait (15)
	script.Parent.Parent.Color = Color3.new(123,0,123)
			
end)

I'm sure the answer is probably pretty simple but I can't seem to find it right now.

1 answer

Nvm, I just used RemoteEvents to tell a server script to delete the sled so the server knows that the sled is gone.

This discussion is preserved as it was. New answers, comments, and votes are closed.