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

How to get the part's properties to change even if its not in the game yet?

So i need this part to change properties once it spawns into the map. It cant change before this because it is not in the map yet. But I dont know how to get the game to detect when it spawns pls help.

function boi()
local point = 0
local part = script.Parent.friendgirl
print("wat da fac")
point = point + 1
if point == 1 then
part.Transparency = 0.5
part.CanCollide = false
end
end
script.Parent.friendgirl.Touched:Connect(boi)


(PROPERTY CHANGE CODE)( DOESNT WORK)

local fucc = script.Parent.spawnm
fucc.MouseButton1Click:Connect(function(hi)
	print("HI")
local noboi = Instance.new("Part", game.Workspace)
noboi.Name = "friendgirl"
noboi.Size = Vector3.new(6,2,6)
noboi.Position = Vector3.new(25,37,43)
noboi.Anchored = false
noboi.BrickColor = BrickColor.Random()
noboi.Material = "Neon"
end)

PART SPAWN CODE (WORKS)

2 answers

Hello there.

Problem: Inserted a part into Workspace but the other script runs before the part is inserted and errors.

Solution: Use :WaitForChild(). It will wait until a given part is loaded.

local function boi()
	local point = 0
	local part = script.Parent:WaitForChild("friendgirl")
	print("wat da fac")
	point = point + 1

	if point == 1 then
		part.Transparency = 0.5
		part.CanCollide = false
	end
end

script.Parent.friendgirl.Touched:Connect(boi)

If it still doesn't work, make sure the part is created on the server, as parts created on the client will no longer replicate to the server due to FilteringEnabled. There are other fixes to this, like RemoteEvents.

Please accept and upvote this answer if it helps.

you use waitforchild to wait until the part has been loaded, you cant get properties of something that doesnt exist. if it doesnt work, make sure the part is created on the server, not the client

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