Title explains it, the client can’t access the models PrimaryPart. I have no clue on how to complete this.
if v:IsA("Model") then
local pos = v:GetPrimaryPartCFrame().Position
print("model")
else
local pos = v.Position
print("ordinary")
end
Title explains it, the client can’t access the models PrimaryPart. I have no clue on how to complete this.
if v:IsA("Model") then
local pos = v:GetPrimaryPartCFrame().Position
print("model")
else
local pos = v.Position
print("ordinary")
end
What exactly are you trying to loop through? The entire workspace? Are there any errors on the Output at all?
It is a loop for positioning trees on the client. The server creates them.
As for the output, this is the main error:
Model:GetPrimaryPartCFrame() failed because no PrimaryPart has been set, or the PrimaryPart no longer exists. Please set Model.PrimaryPart before using this.
You need to set the model PrimaryPart first before you can use that function.
I’m pretty sure he already has a PrimaryPart set up, I believe it’s the issue with detecting it on the client-side rather than on the server
@greipster Can you try printing v.PrimaryPart
on both the client & the server sides?
The client can’t even detect the part inside the model called “Primary”, which is supposed to be the primary part.
Run your game and check if this part is in explorer. Perhaps you forgot to anchor it and it falls to the void.
For some reason, after printing, this is what I get now:
Could you send 36 line of your script called “TreeLoader”?
Is line 36 relevant? It seems that after printing it again, it’s equal to nil
which is a bit strange
The first prints seem to work fine it looks like, but after a millisecond it’s unable to find it? Actually, have you tried calling MakeJoints()
when you clone your Model?
What is makeJoints supposed to do?
Entire function (not relevant)
local function positionTrees()
print("function")
for i, v in pairs(game:GetService("Workspace").Trees:GetChildren()) do
if v and v.Name == "LargeTree" and not (table.find(trees, v)) then
local pos
if v:IsA("Model") then
print(v.PrimaryPart)
local pos = v:GetPrimaryPartCFrame().Position
print("model")
else
local pos = v.Position
print("ordinary")
end
-- [RAYCAST STUFF] --
local rayOrigin = pos
local rayDirection = Vector3.new(0, -1000, 0)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {v, game.Players.LocalPlayer.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if raycastResult then
local targetMaterial = raycastResult.Material
local targetPos = raycastResult.Position
local targetInstance = raycastResult.Instance
table.insert(trees, v)
if targetInstance == game:GetService("Workspace").Terrain and targetMaterial ~= Enum.Material.Water then
v.Position = targetPos + Vector3.new(0, 0, 0)
else
v:Destroy()
end
task.wait(.5)
end
-- -- -- -- -- --
end
end
end
Basically, MakeJoints()
create all the necessary welds for the specified Model so that it doesn’t break and fall down whenever it gets cloned & parented inside the workspace (This is useful for wanting to clone NPC’s onto the workspace and such, as they’re basically moving objects)
Maybe that’s the reason why your PrimaryPart isn’t working, perhaps?
A CFrame has a .position argument, right?
under properties
CFrame has a property called Position lol
Okay I see but try to cut Position and see what will happen
If you look at the script, you will see that I am using the position for raycasting
Have you tried to use Pivot system?
Where is the script located and is this a Script or a LocalScript?