the script i have, or when i publish it, doesn't work, like lets say i publish it as a game, the script doesnt work what i want it to do is, move when i'm not looking, it does that if i dont publish it, but when i publish it it just doesn't move, it does nothing


local DIST = 50 -- How many studs for SCP-173 to notice somebody.
local BLOOD = "Blood" -- The name of the 'Blood' decal, for cleaning.
local SPEED = 1.25 -- How much studs per frame should SCP-173 move.

local pTest = Instance.new('Part') -- Test part, never initialized to world space
pTest.Anchored = true

local move = true
local oldpos = nil

function canSee(target)
	local vec = script.Parent.Position - target.Position
	local isInFOV = (vec:Dot(target.CFrame.lookVector) > 0)
	if (isInFOV) and (vec.magnitude < DIST) then
		local ray = Ray.new(target.Position,vec.unit*200)
		local por = game:GetService('Workspace'):FindPartOnRay(ray,target.Parent,false)
		return (por == nil) or (por:IsDescendantOf(script.Parent.Parent))
	end
	return false
end

local b = ""

function touched(p)
	local pl = game:service('Players'):GetPlayerFromCharacter(p.Parent)
	if pl~=nil then
		if p.Parent:FindFirstChild('Humanoid') then
			script.Parent.Kill:Play()
			script.Parent.Sound:Play()
			p.Parent.Humanoid.Health = 0
			if (b ~= p.Parent.Name) then -- Don't flood with blood
			wait(1) -- Draw Blood
			local bl=script.Parent.Blood:Clone()
			b = p.Parent.Name
			local prt=Instance.new('Part',workspace)
			prt.Name="Blood"
			prt.Anchored=true
			prt.Transparency=1
			bl.Transparency=0
			prt.CanCollide=false
			if p.Parent~=nil then
			prt.CFrame = CFrame.new(p.Parent.Torso.CFrame.X, p.Parent.Torso.CFrame.Y - 0.2, p.Parent.Torso.CFrame.Z)
			end
			prt.Size = Vector3.new(math.random(1,6), 0.5, math.random(1,6))
			bl.Parent=prt
			end
		end
	end
end

script.Parent.Touched:connect(touched)

function point(p1,p2)
	return CFrame.new(p1.Position, Vector3.new(p2.Position.X, p1.Position.Y, p2.Position.Z))
end

while wait(0) do
	move = true
	
	for a,b in pairs(script.Parent:GetTouchingParts()) do
		if b.Size.X < 200 and b~=script.Parent and b~=script.Parent.Parent.Face and b.Name~="Blood" then -- Make sure it's not the floor
			if oldpos~=nil then
				script.Parent.Parent:SetPrimaryPartCFrame(oldpos)
			end
			
			move = false
		else
			-- Breach Script
		end
	end
	
	oldpos = script.Parent.CFrame
	
	for i,v in pairs(game:service('Players'):GetPlayers()) do
		if (v.Character~=nil) then
			if v.Character:FindFirstChild("Torso") then
				local v1,v2,v3 = false, false, false
				local tCf = v.Character.Torso.CFrame
				local mCf = script.Parent.CFrame
				
				if (tCf.X < (mCf.X + DIST) and tCf.X > (mCf.X - DIST)) then
					v1 = true
				end
				if (tCf.Y < (mCf.Y + DIST) and tCf.Y > (mCf.Y - DIST)) then
					v2 = true
				end
				if (tCf.Z < (mCf.Z + DIST) and tCf.Z > (mCf.Z - DIST)) then
					v3 = true
				end
				
				if (v1 and v2 and v3) then
					-- In range
					if (canSee(v.Character.Torso) == false) then
						-- Not in eye blink
						local xDif, zDif = 0, 0
						if v.Character.Torso.CFrame.X~=script.Parent.CFrame.X then
							if math.floor(v.Character.Torso.CFrame.X) > math.floor(script.Parent.CFrame.X) then
								xDif = SPEED
							elseif math.floor(v.Character.Torso.CFrame.X) < math.floor(script.Parent.CFrame.X) then
								xDif = -SPEED
							end
						end
						
						if v.Character.Torso.CFrame.Z~=script.Parent.CFrame.Z then
							if math.floor(v.Character.Torso.CFrame.Z) > math.floor(script.Parent.CFrame.Z) then
								zDif = SPEED
							elseif math.floor(v.Character.Torso.CFrame.Z) < math.floor(script.Parent.CFrame.Z) then
								zDif = -SPEED
							end
						end
						
						local test = CFrame.new(script.Parent.CFrame.X + xDif, script.Parent.CFrame.Y, script.Parent.CFrame.Z + zDif)
						pTest.CFrame = test
						
						if move then
							script.Parent.Parent:SetPrimaryPartCFrame(point(pTest, v.Character.Torso))
							local oldposset = false
							
							--Unstuck
							for a,b in pairs(script.Parent:GetTouchingParts()) do
								if b.Size.X < 200 and b~=script.Parent and b~=script.Parent.Parent.Face then -- Make sure it's not the floor
									if oldpos~=nil and b.Parent:FindFirstChild("Humanoid")==nil and b.Name~="Handle" and b.Name~="Face" and b.Name~="Blood" then
										oldposset = true
										script.Parent.Parent:SetPrimaryPartCFrame(oldpos)
									end
								end
								
								if b.Name=="Handle" then
									b = b.Parent
								end
								
								if oldposset == false and b.Name~="Face" and b.Name~="Blood" then
									touched(b)
								end
							end
						end
					end
				end
			end
		end
	end
end

works if i dont publish it.

1 comment

0

Why are you trying to wait 0 seconds on line 57, at that point why even wait at all