I have a script which creates a part and sets it to my torsos CFrame as an initial placement. I then have a function that cframes that part 100 studs in front of my character. I then check around the area around that part and check for models.
When I check for the parts position (part.CFrame.p), it says that its still at the initial position, which renders my magnitude check around the parts area useless. I have not tried this outside of studio as I have not made it FE compatible yet. Any ideas?
Can we see your script? There’s not much to work with at the moment.
Solved, but I’m still curious to see as to why that happened. What I actually have is a series of parts in a model that launches 100 studs in front of the character. I iterated through the model instead of checking one individual part, which still doesn’t really make sense why it didn’t work
Blockquote
for _, x in pairs (mod:GetChildren()) do
if x:IsA(“MeshPart”) then
for _, v in pairs (workspace:GetChildren()) do
if v.Name == “Noob” then
local atk = v.Atk
if (x.CFrame.p - v.Torso.CFrame.p).magnitude < 30 and atk.Value == false then
coroutine.resume(coroutine.create(function()
atk.Value = true
for i = 1, 20 do game:GetService(“RunService”).Heartbeat:Wait()
v.Humanoid.Health = v.Humanoid.Health - 2
end
atk.Value = false
end))
end
end
end
end
end
Blockquote
Sorry I forgot how to properly block
for _, x in pairs (mod:GetChildren()) do
if x:IsA(“MeshPart”) then
for _, v in pairs (workspace:GetChildren()) do
if v.Name == “Noob” then
local atk = v.Atk
if (x.CFrame.p - v.Torso.CFrame.p).magnitude < 30 and atk.Value == false then
coroutine.resume(coroutine.create(function()
atk.Value = true
for i = 1, 20 do game:GetService(“RunService”).Heartbeat:Wait()
v.Humanoid.Health = v.Humanoid.Health - 2
end
atk.Value = false
end))
end
end
end
end
end
I can’t seem to be able to find any issues in the code provided. However, you should totally NOT be indexing the entirety of the workspace. You’ll most likely add more and more parts to it, slowing down the process and possibly causing lag. Consider placing all noobs within a single folder or model, or maybe tag them using CollectionService.
The issue was most likely present somewhere else in another portion of code. Maybe the part where the positioning was actually being done?
Yeah I don’t plan to index like that for the end product, I’m just trying different methods of detection. Yeah I don’t know much about CollectionService yet, but I heard its great for optimization. Thanks