Round System Problem

I’m making a round system for my racing game but when the map loads in from server storage into a folder called “Active Map” the gameplay scripts such as the hazards on the map don’t work here is an example of one of those scripts. I also keep getting the error for all the gameplay scripts

"Map1 is not a valid member of Folder “Workspace.ACTIVEMAP”

`for i, v in pairs(workspace.ACTIVEMAP.Map1:GetChildren()) do – for all the children of workspace this for loop will run.
if v.Name == “CylKnockback” then – if a child in workspace has the name “GreenPart” it will be destroyed.
local TweenService = game:GetService(“TweenService”)

	local part = v
	
	local info = TweenInfo.new(1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, -1, true)
	local newPosition = part.Position + Vector3.new(-400,0,0)
	local tween = TweenService:Create(part, info, {Position = newPosition})
	tween:play()
end

end

`

The problem is that when the script runs at the start of the game the map isn’t in that folder yet so how do I make it where it won’t run until the map is in that folder?

1 Like

Try using WaitForChild for the map model, then WaitForChild for the items you are looking for.

1 Like

Where do I put that in the code though? I’m kinda just returning to roblox studio so I don’t remember how they work.

I tried this but it made the map not load in

` local mapReady = game.Workspace.ACTIVEMAP:WaitForChild(“Map1”)

for i, v in pairs(workspace.ACTIVEMAP.Map1:GetChildren()) do – for all the children of workspace this for loop will run.
if mapReady then
if v.Name == “CylKnockback” then – if a child in workspace has the name “GreenPart” it will be destroyed.
local TweenService = game:GetService(“TweenService”)

	local part = v
	
	local info = TweenInfo.new(1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, -1, true)
	local newPosition = part.Position + Vector3.new(-400,0,0)
	local tween = TweenService:Create(part, info, {Position = newPosition})
	tween:play()
		
	end

end

end`

Actually nvm i found out the problem I forgot I changed the Map1 to a folder so it was bring up the old model called map1 which had nothing in it. Thank you it works now.

I’d start with putting the greenparts inside a model or folder and then using your GetChildren line to search that folder, not the entire workspace.

I just read your code.

  • don’t restate things like local TweenService = game:GetService(“TweenService”) inside your for loop. State it before the loop so it just has to be specified once.
  • You aren’t looking for a part named “GreenPart” if your line reads if v.Name == "CylKnockback"
    -You aren’t destroying a part, you’re tweening a part’s Position instantly -400 studs. Why tween it when you can just CFrame it there. It’s taking more computing power to do it like that. Tweening is for smooth gradual changes of Properties like Position or Size or Color.

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