I have a model that surrounds the players with parts and in total the model's size is 250x150x250 and what I'm trying to do is make it move forward when all players are more than 150 studs from the back side of it:
game:GetService("Players")
game:GetService("Workspace")
local range = 150
while wait() do
print("StartedLoop")
plrs = game.Players:GetChildren()
for i,plr in ipairs(plrs) do
if plr.Character ~= nil then
local Utorso = plr.Character.UpperTorso
local dist = (script.Parent.Position-Utorso.Position).magnitude
local distance = math.floor(dist)
print("Distance = "..distance.."")
if distance <= (range) then
print("IN RANGE")
wait(5)
else if distance > (range) then
print("OUT OF RANGE")
script.Parent.Parent.Parent.PrimaryPart = script.Parent.Parent.Parent.TopFog
script.Parent.Parent.Parent:SetPrimaryPartCFrame(CFrame.new(script.Parent.Parent.Parent.PrimaryPart.Position + Vector3.new(0,0,1)))
script.Parent.Parent.Parent:SetPrimaryPartCFrame(CFrame.new(script.Parent.Parent.Parent.PrimaryPart.Position + Vector3.new(0,0,0)))
script.Parent.Parent.Parent.PrimaryPart = script.Parent
wait(1)
end
end
end
end
end
The Problem is that when I test it, what seems to happen is that the script detects the distance of the player through the top part of the model (The primary part) rather than from the part at the back of the model like its supposed to. If anyone knows how to fix this I really appreciate the help, I've been trying to make the fog system work for almost 3 hours now. :/
