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

Cloning tool from serverStorage fails 1 out of 10?

For some reason, when running my game, 1 out of 10 times (aproximately), the tool won't be cloned to the backpack when the player connects. No errors in output. Printing "rocket" does return the rocket even when it fails. Am I doing something wrong? is there a better way of doing this? Any suggestion is appreciated:

function LoadData(player)
	local rocketStore = DataStore2("rocket", player)
	local rocketName = rocketStore:GetAsync(""):andThen(function(rocketName)
		if rocketName ~= "" then
			local rocket = game.ServerStorage.RocketItems:WaitForChild(rocketName)			
			if rocket ~= nil then
				local clone = rocket:Clone()
				clone.Parent = player.Backpack
			end
		else
			local rocket = game.ServerStorage.RocketItems:WaitForChild("rocket 1")
			if rocket ~= nil then
				local clone = rocket:Clone()
				clone.Parent = player.Backpack
			end
		end
	end):andThen(function()
		print('get_rocket: success')
	end):catch(function(err)
		warn("get_rocket: " .. err)
	end)
end

game.Players.PlayerAdded:Connect(function(player)
	LoadData(player)
end)

1 answer

I think I have a similar problem: I am making a racing game and have various vehicles in ServerStorage. These are cloned to the starting grid in the beginning of the race. When cloning 3 or more vehicles the 3rd quite often ends up sinking into the ground or wheels folded up, or even glitching away.

I guess the root of the problem is that the chassis of the vehicle does not have time to initialize everything (when multiple vehicles are cloned at the same time) in time for all vehicles and/or some parts are not fully ready so they can go into the ground.

I tried waiting a bit after clone-and-parent to workspace for each vehicle, which seamed to help at first but then it is not 100% reliable. Should I be waiting after the clone and before parenting to workspace? Is that when all the things get created and initialized? Of course you never know how long you have to wait so it would be nice to be able to detect when everything is ready.

How do people solve this problem? Is there a way to make sure the cloned model and all it's parts are all ready to be placed into the workspace?

I would really appreciate it if you could explain in detail how your solution works. Thanks in advance!

1 comment

0

i would be able to help, but i cant read anything.

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