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
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
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.
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
local Part = game.Workspace:WaitForChild("Cube")
local PlayerName = game.Players.LocalPlayer.Name
if PlayerName == "Player1" then
Part.Transparency = 0.5
Part.CanCollide = false
end
It was a good catch but the script still doesn’t do anything
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
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.
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.
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!")
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.