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

Disappearing Plates script keeps breaking, help?

In my minigames, everything goes well... the choosing random minigame, the teleporting, but when a few plates disappear, this comes out in the output:

06:33:40.238 - Transparency is not a valid member of Model 06:33:40.238 - Script 'Workspace.DisappearingPlates.removePlates', Line 25 - local disappearingPlates 06:33:40.239 - Script 'Workspace.DisappearingPlates.removePlates', Line 33 06:33:40.239 - Stack End


-- The function

while wait(1) do
	
local function disappearingPlates()
	
	local plates = script.Parent:GetChildren()
	
	local ranNum1 = plates[math.random(1, #plates)] -- problem :(
	local ranNum2 = plates[math.random(1, #plates)]
	
	--while ranNum1 == ranNum2 do
		--wait()
		--ranNum2 = plates[math.random(1, #plates)]
	--end
	
	for i = 0, 1, 0.05 do
		wait()
		ranNum1.Transparency = i
		ranNum2.Transparency = i
	end
	
	ranNum1:Destroy()
	ranNum2:Destroy()
	
end

	disappearingPlates() -- problem :(
	
end

-- end of script :D

3 comments

0

So please, if you could help out that would be great :)

0

You are indexing the children of a model which contains (probably) Parts, your Script that you wrote up there and, based on error, 1 or more models. You should create a separate model to store only the Parts and index that.

0

Could you show us a picture of the explorer with all folds opened involving the plates.

1 answer

✓ Accepted answer

Your Problem

Your problem is that either ranNum1 or ranNum2 is returning a model. And since you index the Transparency property on line 19 and 20 then it is going to error if either variable is a model due to the fact the models don't have the Transparency property - hence your error Transparency is not a valid member of Model.




Code

--[[You should really consider putting your function on the outside of the while loop, otherwise you're re-defining the function every time the loop iterates.]]

function disappearingPlates()
	local children,plates = script.Parent:GetChildren(),{}
	--Create a table filled only with parts.
	for _,v in next,children do
		if v:IsA("BasePart") then
			table.insert(plates,v)
		end
	end
	--Select randomely from created table
	local ranNum1 = plates[math.random(1, #plates)]
	local ranNum2 = plates[math.random(1, #plates)]
	--Change ranNum2's value as long as it is equal to ranNum1
	while ranNum1 == ranNum2 and wait() do
		ranNum2 = plates[math.random(1, #plates)]
	end
	for i = 0, 1, 0.05 do
		wait()
		ranNum1.Transparency = i
		ranNum2.Transparency = i
	end
	ranNum1:Destroy()
	ranNum2:Destroy()
end

while wait(1) do
	disappearingPlates()
end

2 comments

0

Thanks man, that really helped!

0

Anytime :)

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