LocalScript not changing parts, no errors

Any help would be greatly appreciated! LocalScript is in StarterPlayerScripts

local Model = game.Workspace.Model

	for i, child in ipairs(Model:GetChildren()) do
		if child:IsA("Part")then
			child.Transparency = 0.3
			child.CanCollide = true
		end
	end
1 Like

You would use a regular script for this as a regular script should be the only script accessing parts, not localscripts. You can also just put the script in ServerScriptService and it should work fine.

local Model = workspace.Model

for _, child in pairs(Model:GetChildren()) do
	if child:IsA("Part") then
		child.Transparency = 0.3
		child.CanCollide = true
	end
end
1 Like

It needs to work for the client only for what I’m doing

LocalScripts cannot change properties within a part for everyone in the game unless you use a regular script though.

The code you provided won’t display the child’s Transparency of the value 0.3 and CanCollide won’t be set to true because you are trying to handle it on the client whereas the server is the only one that can change that for everyone in the game hence why I said in my original post.

But I don’t want it to work for everyone, just the client. That’s why I used a localscript

Are you still having issues with this script?

Only way to edit parts from the client is if the parts are made on the client.
Or if the client has network ownership. (Which would change it on the server side as well, not only on the client.)

You would have to make the model on the client side through a script.

Heres an example:

-- Create Model
local Model = Instance.new("Model")

local Parts = {
	[1] = {
		ClassName = "Part",
		Properties = {
			["Size"] = Vector3.new(4, 1, 4),
			["Position"] = Vector3.new(0, 10, 0),
			["Anchored"] = true,
			["CanCollide"] = true,
		}
	}
}

-- Create Parts
for _, Data in pairs(Parts) do
	local New = Instance.new(Data.ClassName)
	
	for prop, value in pairs(Data.Properties) do
		New[prop] = value
	end
	
	New.Parent = Model
end

Model.Parent = workspace

-- Property Changer
for _, child in pairs(Model:GetChildren()) do -- Get The Children Of The Model
	if child:IsA("BasePart") then -- Check If The Child Is A "BasePart"
		child.Transparency = 0.3 -- Set The Transparency
		child.CanCollide = false -- Set The Collision
	end
end
1 Like

uh

local Part = game.Workspace:WaitForChild("Cube") 
local PlayerName = game.Players.LocalPlayer.Name

if PlayerName == "Player1" then
	Part.Transparency = 0.5
	Part.CanCollide = false
end

1 Like

Oh weird cause I tried a different script on the client and it didn’t change the properties at all.

Yeah, it’s gotta be something with this part. If I can’t figure it out I’ll just make a manual list of the parts

You said this was in starter player scripts? Try adding a wait, I believe its running too fast.

1 Like

Oh shoot that’s probably it. Will check rq

1 Like

It was a good catch but the script still doesn’t do anything :frowning:
Thanks though

local Model = game.Workspace:WaitForChild("Model")

for i, child in ipairs(Model:GetChildren()) do
	if child:IsA("Part")then
		child.Transparency = 0.3
		child.CanCollide = false
	end
end
1 Like

There seems to be nothing wrong with your script. Maybe it’s the model itself, the direct children of it may not be “Parts”. Run this and check the output.

for i, child in ipairs(Model:GetChildren()) do
		print(child.ClassName)
	end

If the ClassName of the children are anything other than “Part”, then you need to modify the logic of your code. Calling :IsA only targets the class “Part” and classes that inherit it. Use “BasePart” instead as all other part classes (ie. Part, WedgePart) inherit the class.

Edit : Also should mention the Parts in the model you are attempting to target may not be direct children. They could be children of the model’s children (descendants), in which case you should call :GetDescendants instead.

1 Like

How long did you make the wait, I just tried it with a wait and it works. And yeah try what the guy above me posted, that very well could be it as well if you using things other than roblox’s default part.

1 Like

It’s not printing anything but I tried putting a print statement after that and it went through

local Model = game.Workspace:WaitForChild("Model")

for i, child in ipairs(Model:GetChildren()) do
	if child:IsA("Part")then
		child.Transparency = 0.3
		child.CanCollide = false
	end
end

for i, child in ipairs(Model:GetChildren()) do
	print(child.ClassName)
end

print("Done!")



(Used StarterPlayerScripts)

Thanks for the help!
Fixed by adding a 2-second wait, I thought you meant WaitForChild initially, my bad!

All good glad you got it fixed.

Ngl I’m kind of mad that it worked because WaitForChild is designed to stop that kind of stuff

Yeah, I’ve had an overall bad experience with WaitForChild on roblox, so If something doesn’t work I usually add a wait(2) to the top of the script and it magically works.

1 Like