Model's Part won't change its Anchor values:

Hello,

On Roblox Studio, I decided to make two parts, the first called “TouchedPart” and the second as “TouchedPart2”. Both contain scripts that have the function to fire specific events once being touched, and the goal of them is to clone a model, parent onto a folder and unachor the object’s parts.

While structuring its code lines and testing, it turns out that in a few moments it quite works, yet there are situations that make it unclear to understand… The parts appear to create multiple properties called TouchInterest + print a non-existence script that does not exist in any place of the game.Workspace and/or the touched parts whatsoever.

TouchedPart’s Script:

local Players = game:GetService("Players")

workspace.TouchedPart.Touched:Connect(function(otherPart)
	local maybeCharacter = otherPart.Parent
	local player = Players:GetPlayerFromCharacter(maybeCharacter)
	task.wait(2.75)
	if player then
		local Terrain = workspace.Terrain
		local Clouds = Instance.new("Clouds", Terrain)
		Clouds.Cover = 1
		while Clouds == true do
			break
		end
		
		local Building1 = game.ReplicatedStorage.Building1
		local Build1_Clone = Building1:Clone()
		Build1_Clone.Parent = game.Workspace
		Build1_Clone.Name = "First_Build"
		
		while Build1_Clone.Parent == game.Workspace do
			Build1_Clone.Parent = game.Workspace.GameBuildings.Building1
			break
		end
		
		workspace.TouchedPart.CanCollide = false
		workspace.TouchedPart.CanTouch = false
		workspace.TouchedPart.Script.Enabled = false
	end
end)

TouchedPart2’s Script:

local Players = game:GetService("Players")

workspace.TouchedPart2.Touched:Connect(function(otherPart)
	local maybeCharacter = otherPart.Parent
	local player = Players:GetPlayerFromCharacter(maybeCharacter)
	if player then
		local Terrain = game.Workspace.Terrain
		local Clouds = Terrain:FindFirstChildOfClass("Clouds")
		if Clouds then
			Clouds.Cover = 0.6
			task.wait(2.75)
			Clouds:Destroy()
			while Clouds:Destroy() == nil do
				break
			end
		end
		
		workspace.TouchedPart.CanCollide = true
		workspace.TouchedPart.CanTouch = true
		workspace.TouchedPart.Script.Enabled = true
		
		local Build1_Clone = game.Workspace.GameBuildings.Building1:FindFirstChild("First_Build")
		if Build1_Clone then
			print("success")
			local Build1_Folder = game.Workspace.GameBuildings.Building1
			Build1_Clone.Parent = Build1_Folder
			
			for _, Build1_Folder in pairs(Build1_Folder:GetChildren()) do
				if Build1_Folder:IsA("Folder") and Build1_Folder.Name == "Building1" then
					for _, Parts in pairs(Build1_Clone:GetDescendants()) do
						Parts.Anchored = false
					end
				end
			end
		end
	end
end)

Unknown Script:

local Players = game:GetService("Players")

workspace.TouchedPart2.Touched:Connect(function(otherPart)
	local maybeCharacter = otherPart.Parent
	local player = Players:GetPlayerFromCharacter(maybeCharacter)
	if player then
		local Terrain = game.Workspace.Terrain
		local Clouds = Terrain:FindFirstChildOfClass("Clouds")
		if Clouds then
			Clouds.Cover = 0.6
		end
		task.wait(2.75)
		Clouds:Destroy()
		task.wait(2.75)
		if Clouds == nil then
			print("success")
		end
		workspace.TouchedPart.CanCollide = true
		workspace.TouchedPart.CanTouch = true
		workspace.TouchedPart.Script.Enabled = true
	end
end)

(NOTE: Unknown Script is different from the previous one)


If anyone can help me to solve this little lunatic puzzle, it would be appreciatable a lot! Thank you!!

It is important to take into consideration that all are normal scripts and not LocalScripts…

umm I think the error is in the TouchedPart2’s Script
You have used a while loop giving the condition Clouds:Destroy() == nil which is giving you the error…
that loop ain’t necessary tho.
Still if you want it, you can use this instead

while Clouds == nil do
break
end

but I would suggest to remove that loop unless you are trying to achieve something else from that loop.

1 Like

I actually quite have tried to do these two options, yet somehow the Output prints this error stating that it is attempting to nil using the event :Destroy()… (I am also trying to achieve as not printing this error and getting the descendants of the model’s part so that I can unanchor within the script)

Humping back to this topic to make this reply as solved as discovering the problem… It appears that while developing the environment of the game, there were multiple parts called “TouchedPart2” with the old scripts that I thought it was unknown as printing out of the blue in the Output in errors and lagging the experience.

Thank you @kittyPGR for the little help as possible you could!

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