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

Weird Output for my Map Changer?

I receive the following output after a couple times clickin a brick which starts the script. 22, The Parent property of ChosenOne is locked, current parent: NULL, new parent Workspace Script underneath

local modelGroup = game.ReplicatedStorage:FindFirstChild("Maps"):GetChildren()
local PickedModel = modelGroup[math.random(1, #modelGroup)]
local Model = PickedModel:Clone()
local destroy = game.ServerScriptService.RoundStats.ShouldDestroy
local damage = destroy.Parent.MostDamage

destroy.Changed:connect(function(property)
	if destroy.Value == true then
		--[[ Reset Round Stats ]]--

		destroy.Value = false
		damage.Value = ''
		--[[ End Reset Sequence ]]--

	game.Workspace.ChosenOne:Destroy()
wait(.3)
	----------
local pl = game.Players:GetChildren()
for i=1,#pl do
	pl[i].Character.Humanoid.Health = 0
	----------
Model.Parent = game.Workspace 
Model.Name = 'ChosenOne'
Model:MakeJoints()
end
	else
		end
end)

3 comments

0

I got that same parent error on my question...

0

Has it ever worked before?

0

It works a couple of clicks then it stops. Without problems with continual clicking, no.

1 answer

✓ Accepted answer

That error occurs after you destroy an object game.Workspace.ChosenOne:Destroy() and then try to parent that same object to the workspace.

-If this is the whole script, note that you're only choosing a random map once, which means one server will only ever use one map. Instead, move the lines where you choose the map into the destroy.Changed event, or - if you want the map to activate immediately - into their own function, like this:

local modelGroup = game.ReplicatedStorage:FindFirstChild("Maps"):GetChildren()
local Model
local destroy = game.ServerScriptService.RoundStats.ShouldDestroy
local damage = destroy.Parent.MostDamage
function ActivateNextMap()
	if Model then Model:Destroy() wait(0.3) end --wait is optional, but you had it below
	Model = modelGroup[math.random(1, #modelGroup)]:Clone()
	Model:MakeJoints()
	Model.Parent = workspace
	--If you want, you can set Model.Name here as well, though it's not necessary for this script
end

destroy.Changed:connect(function(property)
	if not destroy.Value then return end
        --[[ Reset Round Stats ]]--
        destroy.Value = false
        damage.Value = ''
        --[[ End Reset Sequence ]]--
	ActivateNextMap()
	----------
	local pl = game.Players:GetChildren()
	for i=1,#pl do
	    pl[i].Character.Humanoid.Health = 0
	end
end)
ActivateNextMap() --thus, 'destroy' doesn't have to become true before the first map is created

Also note that you had some of your code in the player-reset-health loop. Proper indentation shows where everything is.

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